This article will take you to understand the Sentinel mode (Sentine) in Redis, introduce the working mechanism of Sentinel, and how to build the Sentinel mode. I hope it will be helpful to you!
Redis Sentinel Sentinel mode is a distributed system. You can run multiple Sentinel processes (progress) in one architecture. These processes use gossip protocols to Receives information about whether the master server is offline and uses agreement protocols to decide whether to perform automatic failover and which slave server to select as the new master server. [Related recommendations: Redis Video Tutorial]
Redis’ Sentinel system is used to manage multiple Redis servers (instances). The system performs the following three tasks:
Each sentinel sends a PING command to the master, slave and other sentinel instances it knows about once per second.
If the time since the last valid reply to the PING command exceeds the value specified by the down-after-milliseconds option for an instance, the instance will be marked as subjectively offline by sentinel.
If a master is marked as subjective offline, all sentinels that are monitoring the master must confirm that the master has indeed entered the subjective offline state once per second.
When a sufficient number of sentinels (greater than or equal to the value specified in the configuration file) confirm that the master has indeed entered the subjective offline state within the specified time range, the master will be marked as objectively offline
Under normal circumstances, each sentinel will send INFO commands to all masters and slaves it knows once every 10 seconds
When the master is marked as objectively offline by sentinel, the frequency of sentinel sending INFO commands to all slaves of the offline master will be changed from once every 10 seconds to once every 1 second
If there is not enough The number of sentinels agree that the master has been offline, and the master's objective offline status will be removed; If the master returns a valid reply to sentinel's PING command again, the master's subjective offline status will be removed
Environment
master:127.0.0.1:6379 【初始化master】 slave:127.0.0.1:6380 127.0.0.1:6381 sentinel:127.0.0.1:26379 127.0.0.1:26380 127.0.0.1:26381
The installation of redis is omitted here and the sentinel configuration file is modified directly. Corresponding folder Redis6379-Redis6381
# 监控节点,且超过2个sentinel 任务故障,方可执行故障转移 sentinel monitor mymaster 127.0.0.1 6379 2 # 如果节点在 30000毫秒内未回应,就认为故障 sentinel down-after-milliseconds mymaster 30000 # 如果故障转移后,同时进行主从复制数为 1 sentinel parallel-syncs mymaster 1 # 故障转移的超时时间 sentinel failover-timeout mymaster 180000 sentinel deny-scripts-reconfig yes
Start command
./src/redis-sentinel ./config/redis-sentinel-6379.conf(同样启动6380 6381)
For more programming-related knowledge, please visit:Introduction to Programming! !
The above is the detailed content of Let's talk about the Sentinel mode (Sentine) in Redis. For more information, please follow other related articles on the PHP Chinese website!