---restore content starts---
Redis Sentinel
Sentinel (Sentinel) is a tool for monitoring the Master state in a Redis cluster, which has been integrated into the redis2.4+ version
First, Sentinel role:
1): Master Status Detection
2): If Master is abnormal, the master-slave switch is performed, one of the slave as master and the previous master as the Slave
3): After the master-slave switch, the contents of master_redis.conf, slave_redis.conf and sentinel.conf will change, i.e. Master_ Redis.conf will be more than one line slaveof configuration, sentinel.conf monitoring target will be replaced with it
Ii. Sentinel mode of work:
1): Each Sentinel sends a PING command to its known master,slave and other Sentinel instances at a frequency of once per second
2): If an instance (instance) is closer to the last valid PING command than the value specified by the Down-after-milliseconds option, the instance is flagged by Sentinel as a subjective downline.
3): If a master is marked as a subjective downline, all Sentinel that is monitoring this master will confirm that Master has actually entered a subjective downline state at a frequency of once per second.
4): When there is a sufficient number of Sentinel (greater than or equal to the value specified by the profile) to confirm that master does enter the subjective downline status within the specified timeframe, master is marked as objective offline
5): In general, each Sentinel sends an INFO command to all master,slave that it knows at a frequency of every 10 seconds
6): When Master is marked as objective offline by Sentinel, Sentinel sends the INFO command to all Slave of the offline master from 10 seconds to once per second
7): If there is not a sufficient number of Sentinel consent master has been offline, Master's objective offline status will be removed.
If Master re-returns a valid reply to Sentinel's PING command, Master's subjective downline status is removed.
Subjective downline and objective downline
subjective downline: subjectively down, referred to as Sdown, refers to the current Sentinel instance of a Redis server to make a downline judgment.
Objective Downline: Objectively down, referred to as Odown, refers to a number of Sentinel instances on the master server to make Sdown judgments, and through the Sentinel is-master-down-by-addr command to communicate with each other, the resulting The Master server is judged and then turned on failover.
SdownSuitable for master and slave, as long as a Sentinel discovers that Master is in Odown, this sentinel may be selected by other Sentinel and perform an automatic failover operation on the main server of the downline.
OdownOnly for master, for slave Redis instances, Sentinel does not need to negotiate before judging them as a downline, so slave Sentinel will never reach Odown.
Three, configuration:
1: Specify listening master (three nodes)
# vi/main/redis/sentinel.conf
Port 26379
Daemonize Yes
Sentinel Monitor MyMaster 192.168.100.211 6379 2
Sentinel Down-after-milliseconds MyMaster 30000
Sentinel Parallel-syncs MyMaster 1
Sentinel Failover-timeout MyMaster 900000
LogFile "/main/redis/logs/sentinel.log"
#上面配置文件说明如下:
#第一行指定sentinel端口号
#第二行指定sentinel为后台启动
#第三行指定Sentinel去监视一个名为 MyMaster's Master, The IP address of master is 192.168.100.211, the port number is 6379, and the last 2 indicates that when 2 Sentinel detects a master exception, it will be invalidated only if 2 Sentinel determines that master is invalid, and if the number of Sentinel Non-conformance, automatic failover is not performed.
#第四行指定Sentinel判定Master断线的时间. (Units in milliseconds, judged as subjective downline Sdown)
#第五行指定在执行故障转移时, the maximum number of slave can be synchronized with the new master at the same time. This number is set to 1, although the time required to complete the failover is longer, but it is guaranteed that only 1 slave are in a state that cannot handle the command request at a time
2: Launch Sentinel (three nodes):
#/main/redis/src/redis-sentinel/main/redis/sentinel.conf
3: Set boot boot (three nodes)
# echo "/main/redis/src/redis-sentinel/main/redis/sentinel.conf" >>/etc/rc.local
Iv. Points of attention:
1): First boot, you must first start the master
2): Sentinel only switches from server-side, app-side development (e.g. Sentineljedis of Jedis Library, ability to monitor Sentinel status)
3): If Master has been judged as offline, Sentinel has chosen the new master, and has changed old master to slave, but has not changed it to new master. If you restart Old master at this point, the Redis cluster will be in a no Master state, and you can only manually modify the configuration file and then restart the cluster
To this redis cluster configuration is complete
---restore content ends---
Redis cluster hot standby automatic switch Sentinel configuration combat