当前位置:网站首页>Redis sentinel mode
Redis sentinel mode
2022-07-28 01:11:00 【Life goes on and battles go on】
summary
The method of master-slave switching technology is : When the primary server goes down , You need to manually switch a server to the primary server , This requires human intervention , Laborious and arduous , It will also make the service unavailable for a period of time . This is not a way of pushing , More time , We prioritize sentinel mode .Redis from 2.8 It began to officially offer Sentinel( sentry ) Architecture to solve this problem .
Automatic version of usurpation of power , First Redis The order of the sentry , Sentinels are an independent process , As a process , He will run independently , The principle is that the sentry sends orders , wait for Reids Server response , So as to monitor the operation of multiple Redis example .

The Sentinels here have two functions
- By sending commands , Give Way Redis The server returns to monitor its running state , Including the master and slave servers
- When the sentry monitors and sweeps master Downtime , Will automatically slave Switch to master, And then through Publish subscribe mode Notify other slave servers , Modify the configuration file , Let them switch hosts .
But a sentinel process is right Redis The server monitors , There may be problems , So , We can use multiple sentinels to monitor . There will be surveillance between the Sentinels , In this way, the multi sentry mode is formed .

Suppose the primary server goes down , sentry 1 First detect the result , The system doesn't work right away failover The process , Just sentinels 1 Subjectively, the primary server is not available , This phenomenon is called Subjective offline . When the rear sentry also detects that the primary server is not available , And when the quantity reaches a certain value , Then there will be a vote between the Sentinels , The result of the vote was initiated by a sentinel , Conduct failover[ Fail over ] operation . After switching successfully , Through the publish and subscribe mode , Let each sentry switch the host from the server that they monitor , This process is called Objective offline .
Configuration testing
- sentinel monitor The name of the monitored host 127.0.0.1 6379 1se 1
- The last number above 1, After the host is hung up slave Vote to see who takes over as the host , How many tickets to become the host
- Redis-sentinel /wyt/sentinel.conf
- The above directories are configured according to their actual situation , Maybe the directory is different
-bash: redis-sentinel: command not found
# A global command is missing , take /redis/src The executable file under the directory creates a soft connection value path in the environment variable , It's easy for the system to identify , It's like a shortcutln -s /www/server/redis/src/* /usr/local/bin/

If Master The node is disconnected , At this time, a server will be randomly selected from the slave machine

Sentinel log

![]()
If the host comes back at this time , Can only merge under the new host , As a slave , That's the rule of sentinel mode
The advantages and disadvantages of sentinel mode
advantage
- The sentry cluster model is based on the master-slave model , All the advantages of master-slave , Sentinel mode also has .
- Master slave can switch , Faults can be transferred , Better system availability
- Sentry mode is an upgrade of master-slave mode , More robust system , Higher availability .
shortcoming
- Redis Difficult to support online capacity expansion , When the cluster capacity reaches the upper limit, online capacity expansion will become very complex .
- The sentinel configuration mode is not simple , It's even a little cumbersome
Sentry configuration description
#Example sentinel.conf
# sentry sentinel The port on which the instance runs Default 26379
port 26379
# sentry sentinel Working directory of
dir /tmp
# sentry sentinel Monitored redis The master node ip port
#master-name The name of the master node that you can command yourself There can only be letters A-z、 Numbers 0-9, These three characters “. - _” form .
#quorum How many sentinel The Sentinels agreed that master The main node is lovelorn At this time, it is objectively considered that the master node is disconnected
#sentinel monitor <master-name> <ip> <redis-port> <quorum>
sentinel monitor mymaster 127.0.0.1 6379 2
# When in Redis In the example, the requirepass foobared Authorization code So all connections Redis The client of the instance must provide the password
# Set up a sentry sentinel Password to connect master and slave Note that the same verification code must be set for master and slave
#sentinel auth-pass <master-name> <password>
sentinel auth-pass mymaster MySUPER--secret-0123password
# Specify how many milliseconds later The master node didn't answer the sentry sentinel here Sentinels subjectively think that the primary node is offline Default 30 second
#sentinel down-after-milliseconds <master-name> <milliseconds>
sentinel down-after-milliseconds mymaster 30000
# This configuration item specifies when sending failover How many can there be at most during the primary / standby handover slave Simultaneously on the new master Conduct Sync
The smaller the number , complete failover The longer it takes
But if the number is bigger , It means the more slave because replication And is not available
You can do this by setting this value to zero 1 To make sure there's only one at a time slave In a state where command requests cannot be processed .
#sentinel parallel-syncs <master-name> <numslaves>
sentinel parallel-syncs mymaster 1
# Timeout for failover failover-timeout It can be used in the following aspects :
#1、 The same sentinel To the same master two failover The time between
#2、 When one slave From a wrong one master Where the synchronized data starts to calculate the time . until slave Corrected to be correct master Where the data is synchronized
#3、 When you want to cancel an ongoing failover The time required
#4、 When doing failover when , Configure all slaves Point to the new master Maximum time required , however , Even after this timeout ,slaves It will still be correctly configured to point to master, But it won't parallel-syncs Here comes the configured rule
# Default three minutes
#sentinel failover-timeout <master-name> <milliseconds>
sentinel failover-timeout mymaster 180000
#SCRIPTS EXECUTION
# Configure the script to be executed when sending at a certain time , The administrator can be notified by script , For example, when the system is not running normally, send an email to inform the relevant personnel
# There are the following rules for the result of the script :
# If the script returns 1, Then the script will be executed again later , The number of repetitions currently defaults to 10
# If the script returns 2, Or 2 A higher return value , The script will not repeat
# If the script is terminated during execution due to receiving a system interrupt , Then the same return value is 1 The same behavior when .
# The maximum execution time of a script is 60s, If I exceed that time , The script will be a SIGKILL Signal termination , And then re execute
# Notification scripts : When sentinel When any warning level event occurs ( for instance reids Subjective failure and objective failure of examples, etc ), This script will be called , At this point the script should be sent by email ,SMS Wait for the way to inform the system administrator about the abnormal operation of the system . When the script is called , Two parameters will be passed to the script , One is the type of event , One is the description of the event . If sentinel.conf The script path is configured in the configuration file , Then you have to make sure that the script exists in this path , And it's executable , otherwise sentinel Failed to start normally successfully .
# Notification script
#sentinel notification-script <master-name> <script-path>
sentinel notification-script mymaster /var/redis/notify.sh
# The client reconfigures the master node parameter script
# When one master because failover And when it changes , This script will be called , Notify related clients about master Information that the address has changed .
# The following parameters will be passed to the script when the script is called :
#<master-name> <role> <state> <from-ip> <from-port> <to-ip> <tp-port>
# at present <state> Always “failover”
#<role> yes “leader” perhaps “observer” One of them .
# Parameters from-ip,from-port, to-ip,to-port It's for the old master And the new master( I.e. old slave) communication
# This script should be generic , Can be called many times , It's not targeted .
#sentinel client-reconfig-script <master-name> <script-path>
sentinel client-reconfig-scirpt mymaster /var/redis/reconfig.sh
边栏推荐
- 激活最大化
- scrollview、tableView嵌套解决方案
- uni-app进阶之样式框架/生产环境
- Examples of application of JMeter in performance testing
- One year anniversary of creation, Chongba young Lang
- c# 反射之Type使用
- I/O设备的基本概念及分类
- Network equipment hard core technology insider firewall and security gateway (V) security double repair method
- Recommended system model: DSSM twin tower model for embedded recall
- 进程与进程调度
猜你喜欢

Red team killer behinder_ V4.0 (ice scorpion 4.0)

DEMO:测试接口短时间内接收重复数据创建单据

Cross desktop web container evolution
![[300 opencv routines] 241. Scale invariant feature transformation (SIFT)](/img/7a/a764c779c3162920c832325f89f340.png)
[300 opencv routines] 241. Scale invariant feature transformation (SIFT)
![Jericho will make a popping sound when turning on, broadcasting a prompt tone, and turning off [chapter]](/img/e3/ea7278eb855cca2a1af4f96772bcb1.png)
Jericho will make a popping sound when turning on, broadcasting a prompt tone, and turning off [chapter]

IP address & subnet mask

函数相关知识

数组相关知识
![[CruiseControl]Build Result JSP](/img/80/11c2b539c217ecd6ba55668d3e71e9.png)
[CruiseControl]Build Result JSP

代码随想录笔记_哈希_1002查找共用字符
随机推荐
Jericho will make a popping sound when turning on, broadcasting a prompt tone, and turning off [chapter]
Jerry's prompt sound processing when switching devices [chapter]
IP address & subnet mask
Srv6 debut
DC motor winding parameters
福特SUV版“野马”正式下线,安全、舒适一个不落
Matlab 绘制 - 点和向量:向量加减的方法和源码
oracle分组取最大值
Valued at $36billion! SpaceX, which is about to launch its first manned launch, raised $346million
Leetcode:1997. the first day after visiting all rooms [jump DP]
Swoole内存-table详解
Scrollview, tableview nested solutions
UML类图的六大关系,最佳学习理解方式
【原】【爬虫系列】简要获取一下知乎的最热门话题相关主题及描述信息
Starfish Os打造的元宇宙生态,跟MetaBell的合作只是开始
Redis-哨兵模式
自用图床搭建教程
C language programming | single dog topic explanation
[CruiseControl]Build Result JSP
7. Typescript part Foundation