当前位置:网站首页>Redis sentinel mechanism and configuration
Redis sentinel mechanism and configuration
2022-07-02 12:37:00 【Squat in the corner and count the ants】
One 、 Why? Redis There should be sentinel mechanism in the cluster
Redis Master slave replication has one drawback , When master After the outage , The whole cluster will hang up . because redis Itself will not automatically from slave To elect a new master Of .
Our ideal situation is : When master After hanging up , There can be slave Fill in quickly , Automatically switch to master, It does not affect the whole service .
Based on this , Introduced Redis Sentinel(Redis Sentinel mechanism ).
It can be master After hanging up , Automatically from More than one slave In the election of new master, Start working quickly , It saves the trouble of manual switching , Realized redis High availability .
Two 、 After the analog host hangs , Manual switching
1、 Introduction to the environment
Here are four redis, Respectively the ip yes :
master:172.10.0.2
slave1:172.10.0.3
slave2:172.10.0.4
slave3:172.10.0.5
2、 The original master Hang up
adopt netstat -anp|grep 6379 Command found master Of pid, then kill fall .
Go to a few slave Query in info replication, Will find ,master It's already down.
3、 Manually put a slave The election became the new master
choice slave2 Become new master:
(1) Go to slave2 Client execution slave no one command
The order will slave2 And the original master The master-slave relationship is broken , Make yourself... Again master( Of course , This master There is no one slave )
(2) To the other two slave perform slaveof 172.10.0.4 6379 Or configuration slaveof
Be careful requirepass、masterauth、bind Configuration of , And restart 、 Reload the configuration file , Otherwise it may not work .
Although manual mode can also realize switching , But it is inevitable to encounter
‘ Which one is elected for master’,
‘ If it breaks again, it has to be reconfigured ’,
‘ If something else is delayed , Didn't have time to configure , Will be unable to provide services for a long time ’ Other questions ,
therefore , The sentinel mechanism becomes very necessary .
3、 ... and 、 The principle of the sentry mechanism
Redis Sentinel Is a distributed architecture , There are several Sentinel Nodes and Redis Data nodes , Every Sentinel The node will Sentinel Node monitoring , When it finds that the node is not reachable , The node will be marked as offline .

Sentinels gather to monitor redis Whether the master and slave operate normally .
If the slave node hangs , Then the sentinel assembly will make this slave node offline identification ;
If it's the master node that's down , Then the sentinel set will not only make offline identification for the main node , And it will be carried out by all sentinels " negotiation ”, Elect a new master node , To complete automatic failover . After the original primary node returns to normal , The slave node that will become the new master node .
The whole process is completely automatic , No need for manual access .
Four 、 The realization of sentry mechanism
1、 Create three redis-sentinel, Form a sentinel collection
docker run -itd --name redis-sentinel-1 --privileged --net haveyb-network -p 6384:6379 --ip 172.10.0.6 docker-test
docker run -itd --name redis-sentinel-2 --privileged --net haveyb-network -p 6385:6379 --ip 172.10.0.7 docker-test
docker run -itd --name redis-sentinel-3 --privileged --net haveyb-network -p 6386:6379 --ip 172.10.0.8 docker-test
notes :--net haveyb-network Specify a custom network for
2、 Use docker ps -a Command to view the currently created container

3、 Enter the three newly created sentinel Every container of
docker exec -it redis-sentinel-3 bash
4、 modify net.core.somaxconn Value
vi /etc/sysctl.conf
(1) Add the following line of code :
net.core.somaxconn = 32768
(2) load
sysctl -p
5、 modify redis.conf
vi /etc/redis.conf
(1) Modify the parameters bind 127.0.0.1 by 0.0.0.0
bind 0.0.0.0
(2) Set up redis password
requirepass YourPasswordSettings
(3) Load profile
redis-server /etc/redis.conf &
6、 Modify the new three redis-sentinel Of redis-sentinel.conf
vi /etc/redis-sentinel.conf
(1) modify # bind 127.0.0.1 192.168.1.1 by bind 0.0.0.0
bind 0.0.0.0
(2) Delete this line of code
sentinel monitor mymaster 127.0.0.1 6379 2
This line of code is redis By default ( Nothing commented out ), We will configure it later , So just delete it , It will also avoid problems caused by sequence .
(3) Add the following code
sentinel monitor mymaster 172.10.0.2 6379 2
sentinel auth-pass mymaster yourPasswordSettings
sentinel down-after-milliseconds mymaster 3000
explain :
First line of code :
The name of the master node monitored ( Can start at will , This is called master)、IP And port , the last one 2 There are several Sentinel Find a problem , Perform failover . Generally, this number is set to Sentinel Half of the number of nodes plus 1.
However, it is suggested that the name be mymaster( The default is this ), Because if you call it another name , There are several corresponding changes needed .
Second line of code :
Fill in the connection master Your name and password , The default name is used here mymaster, The password should be filled in master Password , I have set it the same here .
Third line of code
Is to set how often the heartbeat is detected , This is set to 3 second
7、 Newly built in three stations respectively redis-sentinel Load the sentry configuration file
redis-sentinel /etc/redis-sentinel.conf &
8、 Verify that the configuration is successful
If something similar to the following figure appears , It means that the sentry configuration is successful

notes : Remove a sentinel pair master Monitoring of , Carry out orders in the sentry
sentinel remove mastername边栏推荐
- Input a three digit number and output its single digit, ten digit and hundred digit.
- OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
- PR 2021 quick start tutorial, learn about the and functions of the timeline panel
- Record the range of data that MySQL update will lock
- There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
- (C language) 3 small Codes: 1+2+3+ · · +100=? And judge whether a year is a leap year or a normal year? And calculate the circumference and area of the circle?
- BOM DOM
- Does C language srand need to reseed? Should srand be placed in the loop? Pseudo random function Rand
- 深拷贝 事件总线
- IPhone 6 plus is listed in Apple's "retro products" list
猜你喜欢

BOM DOM

In development, why do you find someone who is paid more than you but doesn't write any code?

Adding database driver to sqoop of cdh6

Why do programmers have the idea that code can run without moving? Is it poisonous? Or what?

Sparkcontext: error initializing sparkcontext solution

CDA数据分析——AARRR增长模型的介绍、使用

Rust search server, rust quick service finding tutorial

drools中then部分的写法

Deep Copy Event bus

Discrimination of the interval of dichotomy question brushing record (Luogu question sheet)
随机推荐
刷题---二叉树--2
考研英语二大作文模板/图表作文,英语图表作文这一篇就够了
BOM DOM
[old horse of industrial control] detailed explanation of Siemens PLC TCP protocol
[ybtoj advanced training guidance] judgment overflow [error]
WSL 2 will not be installed yet? It's enough to read this article
MySQL indexes and transactions
Discrimination of the interval of dichotomy question brushing record (Luogu question sheet)
线性DP AcWing 899. 编辑距离
What is the relationship between NFT and metauniverse? How to view the market? The future market trend of NFT
There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
js 迭代器 生成器 异步代码处理 promise+生成器 -> await/async
染色法判定二分图 AcWing 860. 染色法判定二分图
drools中then部分的写法
上传文件时,服务器报错:IOFileUploadException: Processing of multipart/form-data request failed. 设备上没有空间
Sweetheart leader: Wang Xinling
Jenkins voucher management
区间DP AcWing 282. 石子合并
Deep Copy Event bus
Initial JDBC programming