Redis Sentinel

2021/10/7 19:10:59

本文主要是介绍Redis Sentinel,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

基于主从基础上,修改redis-sentinel.conf, scp到其他redis机器,再重新启动redis-sentinel.service

[17:33:43 root@localhost ~]#grep -v "^#" /etc/redis-sentinel.conf 


port 26379

daemonize no

pidfile "/var/run/redis-sentinel.pid"

logfile "/var/log/redis/sentinel.log"   -》 sentinel log


dir "/tmp"

sentinel myid fbe3ed27d75c32f1671571684d21af464c2d7588 -》 自动生成的唯一ID

sentinel deny-scripts-reconfig yes

sentinel monitor mymaster 10.0.0.103 6379 2  -》 master IP

sentinel down-after-milliseconds mymaster 3000 -》 投票时间

sentinel auth-pass mymaster 123456 -》 验证





sentinel config-epoch mymaster 1


protected-mode no
supervised systemd
sentinel leader-epoch mymaster 1
sentinel known-replica mymaster 10.0.0.102 6379
sentinel known-replica mymaster 10.0.0.101 6379
sentinel known-sentinel mymaster 10.0.0.101 26379 34e1ca1b533dcc6c8c8fa88101303ce154c42fd7
sentinel known-sentinel mymaster 10.0.0.102 26379 6fcdcac00226e0f45947c58389068db550e879aa
sentinel current-epoch 1

############# 查看结果
[17:31:29 root@localhost ~]#redis-cli -a 123456 -p 26379 info sentinel
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=10.0.0.101:6379,slaves=2,sentinels=3

#####挂掉当前主redis
[17:31:40 root@localhost ~]#killall redis-server
## 在其他redis上面查看sentinel日志
[17:32:52 root@localhost ~]#tail -f /var/log/redis/sentinel.log
1698:X 07 Oct 2021 17:33:25.497 # +sdown master mymaster 10.0.0.101 6379
1698:X 07 Oct 2021 17:33:25.588 # +new-epoch 1
1698:X 07 Oct 2021 17:33:25.588 # +vote-for-leader 6fcdcac00226e0f45947c58389068db550e879aa 1
1698:X 07 Oct 2021 17:33:26.621 # +odown master mymaster 10.0.0.101 6379 #quorum 3/2
1698:X 07 Oct 2021 17:33:26.621 # Next failover delay: I will not start a failover before Thu Oct  7 17:39:26 2021
1698:X 07 Oct 2021 17:33:26.691 # +config-update-from sentinel 6fcdcac00226e0f45947c58389068db550e879aa 10.0.0.102 26379 @ mymaster 10.0.0.101 6379
1698:X 07 Oct 2021 17:33:26.691 # +switch-master mymaster 10.0.0.101 6379 10.0.0.103 6379
1698:X 07 Oct 2021 17:33:26.691 * +slave slave 10.0.0.102:6379 10.0.0.102 6379 @ mymaster 10.0.0.103 6379
1698:X 07 Oct 2021 17:33:26.691 * +slave slave 10.0.0.101:6379 10.0.0.101 6379 @ mymaster 10.0.0.103 6379
1698:X 07 Oct 2021 17:33:29.719 # +sdown slave 10.0.0.101:6379 10.0.0.101 6379 @ mymaster 10.0.0.103 6379

## 通过投票,10.0.0.103成为新的主
[17:32:15 root@localhost ~]#redis-cli -a 123456 -p 26379 info sentinel
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=10.0.0.103:6379,slaves=2,sentinels=3

## 10.0.0.101重启变成slave
[17:34:16 root@localhost ~]#redis-cli -a 123456 -p 26379 info sentinel
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=10.0.0.103:6379,slaves=2,sentinels=3


1698:X 07 Oct 2021 17:34:08.258 # -sdown slave 10.0.0.101:6379 10.0.0.101 6379 @ mymaster 10.0.0.103 6379
1698:X 07 Oct 2021 17:34:18.201 * +convert-to-slave slave 10.0.0.101:6379 10.0.0.101 6379 @ mymaster 10.0.0.103 6379

  



这篇关于Redis Sentinel的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程