我已经设置了四个服务器和哨兵在简单的主从设置中,在四个不同的虚拟机上部署了多个实例。密钥复制工作正常,并且所有 redis 节点都相互识别(我指的是known-sentinel
和known-slave
选项)。
当我尝试模拟故障时,问题出现了。哨兵只是不断告知他们无法选出新的主服务器(故障转移中止未被选中):
12481:X 22 Jun 17:20:05.761 # <__IP1__>:51002 voted for a3ba8d8cd0c15c8b186b44ba529b83d3a8424a42 27
12481:X 22 Jun 17:20:14.140 # -sdown master mymaster <__IP2__> 6379
12481:X 22 Jun 17:20:14.140 # -odown master mymaster <__IP2__> 6379
12481:X 22 Jun 17:20:16.567 # -failover-abort-not-elected master mymaster <__IP2__> 6379
另一件奇怪的事情是,当我在中查询哨兵的状态时redis-cli
,我得到的可用哨兵实例的数量值一直大于实际计数(当然,不能大于 4(对吗?))。
$ redis-cli -p 51001
> info
[...]
master0:name=mymaster,status=ok,address=91.120.59.231:6379,slaves=3,sentinels=8
此外,我不断收到这些-dup-哨兵启动哨兵时的消息:
14563:X 23 Jun 11:10:18.015 * -dup-sentinel master mymaster <__IP_MASTER__> 6379 #duplicate of <__IP_SLAVE2__>:51003 or 65db9ddba84433f71aa77c9263807e6abd939d2c
以下是其中一个哨兵的配置:
daemonize yes
pidfile "/var/run/redis/redis-sentinel.pid"
logfile "/var/log/redis/redis-sentinel.log"
# bind 192.168.1.100 10.0.0.1
# port 26379
port 51004
dir "/var/lib/redis"
sentinel monitor mymaster <__IP_MASTER__> 6379 2
sentinel failover-timeout mymaster 60000
sentinel auth-pass mymaster <___________PASSW___________>
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 55428
# Generated by CONFIG REWRITE
maxclients 4064
sentinel known-slave mymaster <__IP_SLAVE1__> 6379
sentinel known-slave mymaster <__IP_SLAVE2__> 6379
sentinel known-slave mymaster <__IP_SLAVE3__> 6379
sentinel known-sentinel mymaster <__IP_SLAVE1__> 51002 bfea8e89873353d5c1e9ed498b17f298bd6b6082
sentinel known-sentinel mymaster <__IP_MASTER__> 26379 c04fc07022a251e56e81e21dbe018bd471745038
sentinel known-sentinel mymaster <__IP_SLAVE2__> 51003 b5a56eb69abb5893203ecf7b1a7d28ae4aa06ab5
sentinel known-sentinel mymaster <__IP_MASTER__> 51001 be1ff6c9e4a62abea132c24447fd3cb38d221496
sentinel known-sentinel mymaster <__IP_SLAVE1__> 26379 f5a7fd0ee199afc02ffafc0e822363acf5595b1c
sentinel known-sentinel mymaster <__IP_SLAVE2__> 26379 6328962293b7838fa88b9f176b9bc4cc08f2e26d
sentinel current-epoch 26
日志文件并没有提供太多信息……有没有办法让它更详细一点?你知道我在这里遗漏了什么吗?
提前致谢!
顶帖:
检查防火墙设置,应该没问题,当我完全关闭防火墙时仍然出现同样的错误。
答案1
# *** IMPORTANT ***
#
# By default Sentinel will not be reachable from interfaces different than
# localhost, either use the 'bind' directive to bind to a list of network
# interfaces, or disable protected mode with "protected-mode no" by
# adding it to this configuration file.
#
# Before doing that MAKE SURE the instance is protected from the outside
# world via firewalling or other means.
#
# For example you may use one of the following:
#
# bind 127.0.0.1 192.168.1.1
因此,请尝试绑定您的server's IP
。
咕噜!
答案2
旧的哨兵不会从配置中删除。查看文档redis哨兵
执行: SENTINEL RESET mymaster
一会儿,新的主人就选出来了。