当前位置:网站首页>An article takes you to understand the sentinel mode of redis
An article takes you to understand the sentinel mode of redis
2022-07-25 04:59:00 【nginx】

background In the production environment , In order to ensure redis High availability of services , Usually, master-slave will be built . We know that the principle of master-slave is to obtain from the server rdb Full copy of files + Incremental replication of write operations to jointly ensure data consistency , So when configuring the slave server , A very important configuration item is to identify the main server ip And port number , I have to know which server is my master, not , Like in the following figure replicaof To configure .

Easy to understand redis Sentry mode
For the deployment scheme in the figure , If the primary server goes down , We can only intervene manually , Choose a slave server to be the master server again , Then modify the configuration file of the other two slave servers , take replicaof The configuration of is changed to the new primary server address . Manual intervention takes time and effort without saying , what's more , This will make the service unavailable for a period of time . In this case , Sentinel mode came into being .
What is sentinel mode Sentinelredis Sentry mode , It is used in a master-slave cluster environment , If the primary server goes down , It will automatically set one of the slave servers as new master, And put the rest slave The configuration file of is automatically modified , In this way, a new set of master-slave services will be switched , No human intervention is required , And will not affect the use of services .
So how does it work ? First look at the picture below :

Easy to understand redis Sentry mode

Sentinel mode structure diagram
First of all, sentry is a service independent of master-slave service , It is also a cluster service . The sentinel instance will continuously send Ping, The master server receives , Return a valid reply , So the sentinel instance thinks that the server is normal .
Subjective offline Suppose the primary server goes down , sentry 1 Within the specified time ( Configurable ) No valid reply was received from the master server , Then the Sentry will mark the server offline , It's called subjective offline SDOWN.
Note that only one sentinel is marked as offline , In fact, the sentinel did not receive a reply for many reasons , Maybe the server did hang up , It is also possible that the server is not connected , No reply was received due to network reasons , All in all , The failure of a sentinel to receive a reply does not prove that the main server is down .
Objective offline sentry 2 Also sent Ping command , Also did not receive a reply , sentry 2 The primary server will also be marked SDOWN. This is the time ,3 Among the Sentinels 2 Sentinels reported SDOWN, After the Sentinels communicated with each other , It is believed that there are enough instances to prove that the service is no longer available , therefore , The sentinel instance will mark the server as offline ODOWN.
Sufficient quantity here is configurable , Usually half the number of sentinels plus 1, such as 3 Sentinels are set to 2.
Vote for , Fail over When the sentinel instance marks the service as objectively offline , There will be an election . In the remaining slave server instances , Select one as the master node , At the same time, modify the configuration files of other slave servers , Use the new master node as the source of data synchronization , Then restart the service , Finish switching .
thus , A complete sentinel automatic failover process is completed .
springboot Configure one master and multiple slaves + sentry If our environment changes from master-slave to master-slave + sentry , Modifying the configuration is also relatively simple , Comment out the original host and port Configuration of , Replace with the configuration of sentinel , Here's the picture :
Easy to understand redis Sentry mode

It should be noted that , here nodes The sentry cluster is configured in IP+ port , Instead of master-slave nodes , Don't make a mistake .
From the original :
边栏推荐
- [small program practice] first day
- Pychart configuration pyqt5
- Summary and Prospect of aut, the transport layer protocol of sound network -- dev for dev column
- [c language] custom type (structure ~ enumeration ~ Union)
- The 6th "Blue Hat Cup" National College Students' Cyber Security Skills Competition writeup
- Perspective
- Tiny-emitter.js: a small event subscription and Publishing Library
- 盐粒和冰粒分不清
- Luogu p4281 [ahoi2008] emergency gathering / gathering solution
- 数据链路层协议 ——— 以太网协议
猜你喜欢
随机推荐
The strongest JVM in the whole network is coming!
Market regulation
How to publish your own NPM package
数据链路层协议 ——— 以太网协议
如何判断是否遭到DDOS攻击
Unity LOD
Luogu p4281 [ahoi2008] emergency gathering / gathering solution
在开发或调试IP直接方案时需要注意Host的值跟直接的IP要一致
Introduction to CpG control network
【基于stm32f103的SHT30温湿度显示】
Pyg builds GCN to realize link prediction
Leetcode55. Jumping game
Now the operator wants to check the answer details of all user questions from Zhejiang University. Please take out the corresponding data
【浅析STM32之GPIO寄存器(CRL/CRH)配置 】
85 distributed project construction
教你如何定位不合理的SQL?并优化之
etcd学习
[c language] custom type (structure ~ enumeration ~ Union)
5年经验的大厂测试/开发程序员,怎样突破技术瓶颈?大厂通病......
Ffmpeg download and installation







![Introduction to fundamentals of operations research [1]](/img/79/b613bff74a78ad63f202b9e652220d.png)

