MysqL#Redis-Sentinel--Sentinel mode

=====================================================

Introduction to Redis Sentinel

1. Introduction to Sentinel: Redis Sentinel

Sentinel is a tool used to monitor the status of the Master in the redis cluster . It has been integrated in the redis 2.4+ version and is the high availability (HA) solution officially recommended by Redis.

Check the redis version:

[root@kakaops ~]# redis-server --version

[root@kakaops ~]# redis-server -v

yum install redis configuration file

[root@kakaops ~]# vim /etc/redis.conf
[root@kakaops ~]# vim /etc/redis-sentinel.conf

2. Function

1): Master status detection
2): If the Master is abnormal, a Master-Slave switch will be performed. One of the slaves will be used as the Master and the previous Master will be used as the slave.
3): After the master-Slave switch, master_redis.conf, slave_redis.conf And the contents of sentinel.conf will change, that is, there will be an extra line of slaveof configuration in master_redis.conf, and the monitoring target of sentinel.conf will be changed accordingly

3. Working mode

1): Each Sentinel sends a PING command to the Master, Slave and other Sentinel instances it knows once a second

2): If an instance is more than the value specified by the down-after-milliseconds option from the last valid reply to the PING command, the instance will be marked as subjective offline by Sentinel.

3): If a Master is marked as subjectively offline, all Sentinels that are monitoring this Master must confirm that the Master has indeed entered the subjective offline state at a frequency of once per second.

4): When a sufficient number of Sentinel (greater than or equal to the value specified in the configuration file) confirms that the Master has indeed entered the subjective offline state within the specified time range, the Master will be marked as objectively offline

4. Subjective offline and objective offline

Subjectively offline: Subjectively Down, or SDOWN for short, refers to the offline judgment made by the current Sentinel instance on a redis server.
Objective Downline: Objectively Down, or ODOWN for short, refers to the downline of the Master Server after multiple Sentinel instances make SDOWN judgments on the Master Server and communicate with each other through the SENTINEL is-master-down-by-addr command Judge, then turn on failover

Redis sentry mode configuration

1.每台机器上修改redis主配置文件redis.conf文件设置:bind 0.0.0.0   ---已经操作
2.每台机器上修改sentinel.conf配置文件:修改如下配置
[root@redis-master src]# cd ..
[root@redis-master redis]# vim sentinel.conf
sentinel monitor mymaster 10.0.0.137 6379 2 #当集群中有2个sentinel认为master死了时,才能真正认为该master已经不可用了。 (slave上面写的是master的ip,master写自己ip)
如果主库有密码,就写在这里,如果想想给哨兵设置密码,就需要设置成和主库一样的
sentinel auth-pass <master-name> <password>
sentinel down-after-milliseconds mymaster 3000   #单位毫秒
sentinel failover-timeout mymaster 10000   #若sentinel在该配置值内未能完成failover(故障转移)操作(即故障时master/slave自动切换),则认为本次failover失败。
protected-mode no  #关闭加密模式--新添加到sentinel配置文件中
3.每台机器启动哨兵服务:
[root@redis-master redis]# ./src/redis-sentinel sentinel.conf
注意:在生产环境下将哨兵模式启动放到后台执行:     ./src/redis-sentinel sentinel.conf &

Insert picture description here

^C4854:signal-handler (1564349039) Received SIGINT scheduling shutdown...
4854:X 29 Jul 05:23:59.592 # User requested shutdown...
4854:X 29 Jul 05:23:59.592 # Sentinel is now ready to exit, bye bye...
[root@redis-master redis]# systemctl stop redis.service

View on the slave machine:
Insert picture description here
log in to the slave server to see if there is any switch
Insert picture description here

Guess you like

Origin blog.csdn.net/kakaops_qing/article/details/109262567