当前位置:网站首页>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 :
边栏推荐
- QT download installation tutorial
- Leetcode55. Jumping game
- 阿亚的角度思考
- 读书的思考
- [untitled]
- How to ensure data consistency between MySQL and redis?
- ESWC 2018 | r-gcn: relational data modeling based on graph convolution network
- Open source summer interview | "after 00" PMC member Bai Zeping
- STM32 development note 117: generate IIR low-pass filter coefficients using MATLAB
- 市场的调节
猜你喜欢

QT download installation tutorial

Ora-01460: conversion request cannot be implemented or unreasonable

Actual combat | record an attack and defense drill management

This low code reporting tool is needed for data analysis

Druid connection pool - strong self-study from 0. Those who don't understand Druid can click in. If you know not to click in, you will think I'm wordy

Summary and Prospect of aut, the transport layer protocol of sound network -- dev for dev column

推荐系统-协同过滤在Spark中的实现

Docker builds MySQL master-slave replication

Data link layer protocol -- Ethernet protocol
![[c language] custom type (structure ~ enumeration ~ Union)](/img/24/f4ccccef5977c6f465284402487fa2.png)
[c language] custom type (structure ~ enumeration ~ Union)
随机推荐
If you don't know these 20 classic redis interview questions, don't go to the interview!
Pyg builds GCN to realize link prediction
读书的思考
Json.tojsonstring cannot pass Boolean
【基于stm32f103的SHT30温湿度显示】
Token value replacement of burpsuite blasting
[ CTF 学习 ] CTF 中的隐写集合 —— 图片隐写术
Libenent and libev
How can I check if the number of RDS links in MySQL suddenly rises?
看问题的角度
【浅析STM32之GPIO寄存器(CRL/CRH)配置 】
Deep understanding of pod
数据链路层协议 ——— 以太网协议
It we media shows off its wealth in a high profile, and is targeted by hacker organizations. It is bound to be imprisoned
小说抓取实战
Docker builds MySQL master-slave replication
mitt.js:小型事件发布订阅库
Logu p3398 hamsters find sugar solution
OA and fansoft Bi cross system users, departments and posts synchronous summary
Unity LOD