当前位置:网站首页>Sentinel mode of redis
Sentinel mode of redis
2022-07-06 09:14:00 【~Pompeii】
Catalog
Redis Sentinel mode
1. The sentry introduces
sentry (sentinel) It's a distributed system , It is used to monitor each server in the master-slave structure , When there is a failure, the voting mechanism is used to select a new one aster And put all slave Connect to the new master.
2. Sentinel role
1. monitor
Keep checking master and slave Is it working .
master Survival tests 、master And slave Operation detection
2. notice ( remind )
When there is a problem with the monitored server , To the other ( The sentry room , client ) Sending notice .
3. Automatic failover
To break off master And slave Connect , Pick one slave As master, Will others slave Connect to the new master, And inform the client of the new server address
Be careful :
The sentry is also a redis The server , It just doesn't provide data services
Usually, the number of sentinels is an odd number ( Usually at least three )
3. Sentinel related configuration
notes : In general rdb file 、aof file 、” Some work information of the sentry “ All exist under a directory , Even those of different ports are saved in a directory ;
sentinel.conf And redis-conf The files are also stored in a directory , Even for different ports sentinel.conf And redis-conf Files are also saved in a directory
1.port 26379:
Sentinels usually default to 26379
2.dir “/var/lib/redis”:
Store some work information of the sentry
3.sentinel monitor :
Give Way sentinel To monitor an address ip:port The primary server of , there master-name You can customize ; It's a number , Indicates how many sentinel When the primary server is considered down , It's the real downtime , It is usually considered that the host has been down when the number is half or more , Need basis sentinel Quantity settings for .
4.sentinel monitor mymaster 127.0.0.1 6379 2:
Monitoring host ,mymaster This word can be changed , Name can be customized
2 Refer to 2 If a sentinel decides that the host is hung, it will be considered that the host is hung , Equivalent to a standard , Usually set to half the number of sentinels plus 1, This is why the number of our sentinels is usually set to an odd number ( Setting up 3 When I was a sentinel , Yes 2 A sentry thought the main engine was down , I think the host is down )(3 Sentry configuration 2)(5 Sentry configuration 3)(7 Sentry configuration 4)
5.sentinel down-after-milliseconds :
Within the specified number of milliseconds , If the master node does not answer the Sentinel's PING command , At this time, the sentry thinks the server is offline , The default time is 30 second . And mymaster There needs to be a one-to-one correspondence , Is in milliseconds
6.sentinel parallel-syncs :
Specify how many Redis The service synchronizes the new host , That is, how many redis Start synchronizing data at the same time , generally speaking , The smaller the number, the longer the synchronization time , And the bigger , The higher the requirements for network resources .
7.# sentinel auth-pass mymaster MySUPER–secret-0123passw0rd:
sentinel auth-pass < Server name >< password >
If the master server has a password , Then the sentry must also be configured with a password , Otherwise, the sentinel cannot monitor the master-slave server . This password is the same as the master server password .
8.# sentinel failover-timeout :
Specify the number of milliseconds allowed for failover , If you exceed this time , The failover execution is considered to have failed , The default is 3 minute .
4. Deploy sentinels
1) Configure the master-slave structure of one drag two
2) Three sentries ( The configuration is the same , Different ports )
3) see sentinel.conf
notes : The starting sequence is , Start the host first , Restart the slave and then the sentry
The order to start the sentry is as follows :
redis-sentinel sentinel- Port number .conf
5. demonstration ( Deploy sentinels )
Created 3 A sentinel , One master,2 individual slave.
“ sentry 1”、“ sentry 2“、” sentry 3“ The window is used to view the log ;
You can see there's one sentinel.conf The configuration file
Copy sentinel.conf The configuration file , And modify it to sentinel-26379.conf、sentinel-26380.conf、sentinel-26381.conf:
see redis-6379.conf、redis-6380.conf The configuration file
establish redis-6381.conf The configuration file
start-up 6379master host 、6380slave Slave 、6381salve Slave 、:
start-up 26379 sentry
You can enter the sentry 26379 Client to view key namely get operation , However, it is not allowed to set operation ;
just so so info Check the information
Look again 26379 The configuration file , I found a lot of new information added , That is, once the sentinel is activated , Its configuration file information will change
start-up 26380 sentry :
Which one can you see from the last line id Namely 26379 Sentinel's id 了
Look again 26379 Sentinel log , I also found that there is an extra line , yes 26380 Sentinel's id, That means sentinels can communicate with each other
Look again 26379 The configuration file , I found that the information inside has changed again
start-up 26381 sentry
Look again 26379 The configuration file , I found that the information inside has changed again
ctrl+c Stop 6379master host
30 Seconds later ,26379 The sentry began to print a large number of logs
Vote in the election , Give Way 6381 When the host , Give Way 6379、6380 When slave , This is master-slave switching , however 6379 It's still offline , Once again sdown 6379
6. Master slave switching process
The sentry goes through three stages in the process of master-slave switching
1. monitor :
Sync information
2. notice :
Stay connected
3. Fail over :
1) Find the problem
2) Campaign leader
3) Choose new master
4) new master In office , other slave Switch master, primary master As slave Connect after fault recovery
7. Phase I monitoring phase
For sentinels and master Better information exchange , Build a cmd Connect ( Equivalent to channel )
master It will also generate a “SentinelRedisInstance” Information , And ""SentinelState“ It's almost exactly the same
the second sentinel After coming , Will find “SentinelRedisInstance” Information , In this way, you will know the information of other sentinels
The first one at this time sentinel Only one sentry's message , however sentinel There are two sentry messages , In order to ensure the synchronization between sentinels , Set up ” Publish subscribe channel “, In this way, information can be symmetrical to each other
In order to ensure the long-term symmetry between the first sentry and the second sentry , They need ping Command to maintain
8. Stage 2 notification stage
The first time may be sentinel1 send out hello to master And slave, After receiving the reply, forward it to other sentinels , The second time may be sentinel2 send out hello to master And slave, After receiving the reply, forward it to other sentinels
9. Phase III failover phase
1. Select the alternative from the server list master
1) Not online
2) Slow response
3) And the original master Disconnected for a long time
4) The principle of priority
4.1) priority
4.2)offset
4.3)runid
2. Send instructions ( sentinel )
1) To the new master send out slaveof no one
2) To the other slave send out slaveof new masterIP port
One sentinel Mark that the host is hung up sdown, More than half sentinel Mark that the host is offline odown
边栏推荐
- Mise en œuvre de la quantification post - formation du bminf
- AcWing 2456. 记事本
- LeetCode:387. The first unique character in the string
- Kratos战神微服务框架(三)
- 一篇文章带你了解-selenium工作原理详解
- Multivariate cluster analysis
- Using C language to complete a simple calculator (function pointer array and callback function)
- Redis之核心配置
- go-redis之初始化连接
- Advance Computer Network Review(1)——FatTree
猜你喜欢
Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find
LeetCode:221. Largest Square
Intel distiller Toolkit - Quantitative implementation 2
BN folding and its quantification
Different data-driven code executes the same test scenario
Advance Computer Network Review(1)——FatTree
什么是MySQL?MySql的学习之路是怎样的
Reids之删除策略
Selenium+pytest automated test framework practice
Advance Computer Network Review(1)——FatTree
随机推荐
Improved deep embedded clustering with local structure preservation (Idec)
【shell脚本】使用菜单命令构建在集群内创建文件夹的脚本
什么是MySQL?MySql的学习之路是怎样的
Leetcode刷题题解2.1.1
Redis之Bitmap
Notes 01
go-redis之初始化连接
[text generation] recommended in the collection of papers - Stanford researchers introduce time control methods to make long text generation more smooth
BMINF的后训练量化实现
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
Redis之持久化实操(Linux版)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Cesium draw points, lines, and faces
xargs命令的基本用法
Improved deep embedded clustering with local structure preservation (Idec)
Selenium+Pytest自动化测试框架实战
Advance Computer Network Review(1)——FatTree
KDD 2022 paper collection (under continuous update)
QML control type: menu
【图的三大存储方式】只会用邻接矩阵就out了