当前位置:网站首页>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
边栏推荐
- Matlab 绘制 - 点和向量:向量加减的方法和源码
- [STM32] watchdog module
- 一周年创作纪念日,冲吧少年郎
- Leetcode - find the median of two positively ordered arrays
- scrollview、tableView嵌套解决方案
- Postman 的使用
- swoole-WebSocket服务
- Iperf installation and use
- R language uses ggplot2 visualization: use ggpattern package to add custom stripe patterns, shadows, stripes, or other patterns or textures to the grouped bar graph
- LSB steganography
猜你喜欢

Multithreading & high concurrency (the latest in the whole network: interview questions + map + Notes) the interviewer is calm
![Jerry, if you turn on Bluetooth again, one for two. When the mobile phone is connected to the prototype, it will appear and cannot be connected [chapter]](/img/6c/d4a45981a7fc87f6a82a91017f8ce8.png)
Jerry, if you turn on Bluetooth again, one for two. When the mobile phone is connected to the prototype, it will appear and cannot be connected [chapter]
![[proteus simulation] 51 single chip microcomputer washing machine simulation control program](/img/a1/d4256a5e350078b791c0b5cd512fe3.png)
[proteus simulation] 51 single chip microcomputer washing machine simulation control program

DC motor winding parameters

Jointly create a new chapter in cultural tourism | xinqidian signs a strategic cooperation agreement with Guohua cultural tourism

110. SAP UI5 FileUploader 控件深入介绍 - 为什么需要一个隐藏的 iframe

Rancher2.6 monitoring grafana docking LDAP

The most detailed summary of common English terms in the chip industry (quick grasp of graphics and text)

Jmeter在性能测试中的应用实践样例

Interface test practical project 02: read interface test documents and practice
随机推荐
Leetcode:1997. the first day after visiting all rooms [jump DP]
如果某个表有近千万数据,CRUD比较慢,如何优化
At least 42 employees are infected with novel coronavirus! Nokia announces closure of telecom equipment plant in India
Network equipment hard core technology insider firewall and security gateway (V) security double repair method
Syntaxerror resolved: positive argument follows keyword argument
0-1背包问题
Multithreading & high concurrency (the latest in the whole network: interview questions + map + Notes) the interviewer is calm
MySQL中的运算符
Leetcode - find the median of two positively ordered arrays
Srv6 debut
范德蒙德卷积 学习笔记
Oracle错误: ORA-01722 无效数字
Valued at $36billion! SpaceX, which is about to launch its first manned launch, raised $346million
Thesis appreciation [iclr18] a neural language model combining syntax and vocabulary learning
C type use of reflection
Basic use of calculation attributes
Ford SUV "Mustang" officially went offline, safe and comfortable
iperf安装与使用
估值360亿美元!即将进行首次载人发射的SpaceX筹资3.46亿美元
Jerry caused other messages to accumulate in the message pool [article]