当前位置:网站首页>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.
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-yDIlZWmP-1656665781972)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701160545617.png)]](/img/5d/56915e0360187eae51b598cc1f8b02.png)
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
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-VHpftmPR-1656665781973)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701161621170.png)]](/img/9b/6682633befa137e88ed51838a05d56.png)
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
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-YoqnEZqB-1656665781974)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701161653920.png)]](/img/24/1566a08f5781978ded0fdc3454ff61.png)
Copy sentinel.conf The configuration file , And modify it to sentinel-26379.conf、sentinel-26380.conf、sentinel-26381.conf:
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-ojinpvGt-1656665781974)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701162232749.png)]](/img/b7/9014c5e785d653a26a78d06bbdd1e5.png)
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-aT5SBEFd-1656665781975)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701162246139.png)]](/img/54/b8d5a5ba35137e2de1b0d945e92e55.png)
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-Zif9yi0G-1656665781975)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701162252929.png)]](/img/88/14634885d0d6aef18fe0b95ba1381e.png)
see redis-6379.conf、redis-6380.conf The configuration file
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-8wrvDK8s-1656665781976)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701162429879.png)]](/img/01/dbe88229b59b1ab4b8c463a956070a.png)
establish redis-6381.conf The configuration file
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-1L162aa4-1656665781976)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701162455852.png)]](/img/04/b2afbc9a836f9d322f42ff3744d6ab.png)
start-up 6379master host 、6380slave Slave 、6381salve Slave 、:
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-t1wqvdC0-1656665781977)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701162555747.png)]](/img/1e/819e839447f085bb61b08c27b20bd8.png)
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-kPEU0DeO-1656665781977)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701162603987.png)]](/img/c3/0186729dc929218d040ad2d2d02572.png)
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-K24buOuP-1656665781978)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701162610228.png)]](/img/3d/5d47f581bc292d5ae6d792eaf99ea0.png)
start-up 26379 sentry
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-6Lfsm0PA-1656665781978)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701162815038.png)]](/img/c5/a31e4bf8d6f9388b02309ed331b38b.png)
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
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-fktuv9wR-1656665781978)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701162843707.png)]](/img/73/0aa5425d47477135be4adbf1dd02be.png)
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-Q2UY14kB-1656665781979)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701162852757.png)]](/img/59/902ae3a88247a2583b7d556a343776.png)
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
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-YzJytuVl-1656665781979)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701162910628.png)]](/img/3a/c740127b65951bd012722c9ac265b0.png)
start-up 26380 sentry :
Which one can you see from the last line id Namely 26379 Sentinel's id 了
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-wu3FlwrD-1656665781980)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701162939149.png)]](/img/32/535302a18583d03404071fb464578e.png)
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
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-PIfgvURo-1656665781980)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701162958908.png)]](/img/8e/e433af180ab860935284f4ea6c44dc.png)
Look again 26379 The configuration file , I found that the information inside has changed again
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-Jx7V1EOc-1656665781981)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701163017227.png)]](/img/55/8e929470afd866894083965d0f4604.png)
start-up 26381 sentry
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-PffR9O08-1656665781981)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701163039989.png)]](/img/a9/dfffe88a5ebea539d885e53a2e48fd.png)
Look again 26379 The configuration file , I found that the information inside has changed again
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-XR9z3UOQ-1656665781982)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701163052800.png)]](/img/9c/ef05620b786e87b71ab462068ee225.png)
ctrl+c Stop 6379master host
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-I3fnvKA2-1656665781982)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701163111289.png)]](/img/31/59676d6e0dc70d5f01804069bae1f9.png)
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
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-GKGn41rS-1656665781983)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701163150958.png)]](/img/25/d1bf8945cdb5a084ff6502102269c5.png)
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
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-3y3FNCw4-1656665781983)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701163320039.png)]](/img/a6/e2f7698c42c35744491a31437e0b22.png)
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
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-Oye2JN4t-1656665781984)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701163843356.png)]](/img/6c/837e5ff753aafe062e7af4d3f30e6d.png)
the second sentinel After coming , Will find “SentinelRedisInstance” Information , In this way, you will know the information of other sentinels
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-NTRmwgAE-1656665781984)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701164133165.png)]](/img/7f/4f3a3b3c69e3a11cc80386393bbd72.png)
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
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-Qmxhr7Xz-1656665781984)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701164313686.png)]](/img/7c/d03e6b818c076ac92d370fb64e6c21.png)
In order to ensure the long-term symmetry between the first sentry and the second sentry , They need ping Command to maintain
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-DRsHiPBv-1656665781985)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701164935125.png)]](/img/2d/da31b2f3be63a1c49e70065b3a5452.png)
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
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-Yx6O2h3s-1656665781985)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701165004024.png)]](/img/c2/51faa70c4dd7aba19300775e157439.png)
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
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-VzWgL98s-1656665781985)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701165511443.png)]](/img/97/1e0a5c647103f3cfc3e56edc9f1b55.png)
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-8Q8ZtX7Z-1656665781986)(C:/Users/86158/AppData/Roaming/Typora/typora-user-images/image-20220701165544555.png)]](/img/d4/87db01e0ab8cfcc66843456d7bd79b.png)
边栏推荐
- Redis之核心配置
- Notes 01
- Redis之持久化实操(Linux版)
- [Hacker News Weekly] data visualization artifact; Top 10 Web hacker technologies; Postman supports grpc
- Implement window blocking on QWidget
- Improved deep embedded clustering with local structure preservation (Idec)
- [sword finger offer] serialized binary tree
- Kratos战神微服务框架(三)
- 如何正确截取字符串(例:应用报错信息截取入库操作)
- 什么是MySQL?MySql的学习之路是怎样的
猜你喜欢

Pytest之收集用例规则与运行指定用例

In depth analysis and encapsulation call of requests

【剑指offer】序列化二叉树

BMINF的後訓練量化實現
![[OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)](/img/af/a44c2845c254e4f48abde013344c2b.png)
[OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)

Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find

Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges

一篇文章带你了解-selenium工作原理详解
![[text generation] recommended in the collection of papers - Stanford researchers introduce time control methods to make long text generation more smooth](/img/10/c0545cb34621ad4c6fdb5d26b495ee.jpg)
[text generation] recommended in the collection of papers - Stanford researchers introduce time control methods to make long text generation more smooth

LeetCode:221. Largest Square
随机推荐
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
Leetcode: Sword finger offer 48 The longest substring without repeated characters
不同的数据驱动代码执行相同的测试场景
CSP salary calculation
[sword finger offer] serialized binary tree
AcWing 2456. 记事本
LeetCode41——First Missing Positive——hashing in place & swap
Cesium draw points, lines, and faces
[MySQL] limit implements paging
CUDA实现focal_loss
[daily question] Porter (DFS / DP)
CUDA realizes focal_ loss
BN folding and its quantification
requests的深入刨析及封装调用
[shell script] use menu commands to build scripts for creating folders in the cluster
【剑指offer】序列化二叉树
Redis之核心配置
Advance Computer Network Review(1)——FatTree
使用标签模板解决用户恶意输入的问题
在QWidget上实现窗口阻塞