当前位置:网站首页>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
边栏推荐
- 趣味 面试题
- spfa AcWing 851. spfa求最短路
- Anti shake throttle
- The differences and relationships among port, targetport, nodeport and containerport in kubenetes
- Fastdateformat why thread safe
- AI mid stage technology research
- ThreadLocal的简单理解
- H5 to app
- Docker-compose配置Mysql,Redis,MongoDB
- Less than three months after the programmer was hired, the boss wanted to launch the app within one month. If he was dissatisfied, he was dismissed immediately
猜你喜欢
记录一下MySql update会锁定哪些范围的数据
分布式机器学习框架与高维实时推荐系统
In development, why do you find someone who is paid more than you but doesn't write any code?
寻找二叉树中任意两个数的公共祖先
Docker-compose配置Mysql,Redis,MongoDB
SparkContext: Error initializing SparkContext解决方法
Floyd AcWing 854. Floyd求最短路
Map and set
染色法判定二分图 AcWing 860. 染色法判定二分图
kubenetes中port、targetPort、nodePort、containerPort的区别与联系
随机推荐
深拷貝 事件總線
In development, why do you find someone who is paid more than you but doesn't write any code?
刷题---二叉树--2
Go学习笔记—基于Go的进程间通信
Leetcode - < dynamic planning special> Jianzhi offer 19, 49, 60
CDH存在隐患 : 该角色的进程使用的交换内存为xx兆字节。警告阈值:200字节
Intel 内部指令 --- AVX和AVX2学习笔记
WSL 2 will not be installed yet? It's enough to read this article
Map和Set
Win10 system OmniPeek wireless packet capturing network card driver failed to install due to digital signature problem solution
spfa AcWing 851. spfa求最短路
Lombok common annotations
上传文件时,服务器报错:IOFileUploadException: Processing of multipart/form-data request failed. 设备上没有空间
OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
2.7 binary tree, post order traversal - [FBI tree]
Error in kubeadm join: [error port-10250]: port 10250 is in use [error fileavailable--etc kubernetes PKI
中国交通标志检测数据集
Deep understanding of P-R curve, ROC and AUC
线性DP AcWing 898. 数字三角形
Input box assembly of the shutter package