【Sentinel Mode】

sentinel mode

effect

Monitor whether the host is faulty in the background, and automatically convert the slave library to the main library according to the number of votes

copy delay

Since all write operations are performed on the Master first, and then updated to the Slave synchronously, there is a certain delay in synchronizing from the Master to the Slave machine. When the system is very busy, the delay problem will be more serious, and the number of Slave machines will increase. It will also make this problem worse.

election strategy

1. Select the server with the highest priority. The priority is configured in the replica-priority configuration in the redis.conf file. The default is 100, and the smaller the value, the higher the priority.
2. Choose the one with the largest offset. The offset refers to the most complete data obtained from the original host.
3. Select the slave server with the smallest runid. After each redis instance is started, a 40-digit runid is randomly generated.

configuration

#首先停止redis服务
redis-cli shutdown

#然后再重新启动三台 Redis 服务器,并实现一主双从。
#最后在 /rediscluster 目录下新建 sentinel.conf 文件,文件名称不能写错,必须叫这个名称。
[root@localhost rediscluster]# vim sentinel.conf
#内容如下:
sentinel monitor redismaster 192.168.40.128 6379 1
参数说明:
monitor:监控
redismaster:为监控对象起的服务名称
1:为至少有多个个哨兵同意迁移的数量

#启动sentinel
[root@localhost rediscluster]# redis-sentinel sentinel.conf 
#再启动6379、6380、6381
[root@localhost rediscluster]# redis-server redis_6379.conf 
[root@localhost rediscluster]# redis-server redis_6380.conf 
[root@localhost rediscluster]# redis-server redis_6381.conf
192.168.40.128:6380> slaveof 192.168.40.128 6379
OK
192.168.40.128:6381> slaveof 192.168.40.128 6379
OK

#监控到了6380和6381
1546:X 17 Jul 14:57:11.422 * +convert-to-slave slave 192.168.40.128:6380 192.168.40.128 6380 @ redismaster 192.168.40.128 6379
1546:X 17 Jul 14:57:13.484 * +convert-to-slave slave 192.168.40.128:6381 192.168.40.128 6381 @ redismaster 192.168.40.128 6379

#将6379shutdown
192.168.40.128:6379> shutdown

#将6380变为主,在6379上创建的数据还在
1546:X 17 Jul 15:02:05.174 * +failover-state-send-slaveof-noone slave 192.168.40.128:6380 192.168.40.128 6380 @ redismaster 192.168.40.128 6379
192.168.40.128:6380> info replication
# Replication
role:master

#重启6379
[root@localhost rediscluster]# redis-server redis_6379.conf 
[root@localhost rediscluster]# redis-cli -h 192.168.40.128 -p 6379
#变为从,主为6380
192.168.40.128:6379> info replication
# Replication
role:slave
master_host:192.168.40.128
master_port:6380

Guess you like

Origin blog.csdn.net/HealerCCX/article/details/131767390