我已经在端口7000、7001和7002(一个主服务器和两个从服务器)上设置了redis sentinel,在端口26379、26380和26381上设置了三个sentinel,它们都在同一台机器(ubuntu vm)上。
当我启动它们时,根据日志,一切看起来都很好,当我对哨兵运行info命令时,看起来也很健康。但是当我放下主服务器(通过ctrl+c或redis cli sleep命令使其停止工作)时,没有一个从服务器实例被引入为新的主服务器,哨兵试图指定并连接到已经死掉的主服务器实例!我的配置如下:
主人:

port 7000
protected-mode no

从机1:
port 7001
slaveof 10.75.196.216 7000

从机2:
port 7002
slaveof 10.75.196.216 7000

哨兵1:
port 26379
protected-mode no

sentinel myid bdddadb6e825065398be0bae214891d7ccbd6e2a
sentinel monitor themaster 10.75.196.216 7000 2
sentinel down-after-milliseconds themaster 3000
sentinel failover-timeout themaster 5000
sentinel parallel-syncs themaster 2
sentinel config-epoch themaster 0

# Generated by CONFIG REWRITE
dir "/home/bob/app/sentinel-test/master"
sentinel leader-epoch themaster 322
sentinel known-slave themaster 10.75.196.216 7002
sentinel known-slave themaster 10.75.196.216 7001
sentinel known-sentinel themaster 10.75.196.216 26380 181fb84351d6b96e0120bfa68331738ef111c49f
sentinel known-sentinel themaster 10.75.196.216 26381 8497ee90c1e4525c0f957407fefa77427f427e0d
sentinel current-epoch 322

哨兵2:
port 26380
protected-mode no

sentinel myid 181fb84351d6b96e0120bfa68331738ef111c49f
sentinel monitor themaster 10.75.196.216 7000 2
sentinel down-after-milliseconds themaster 3000
sentinel failover-timeout themaster 5000
sentinel parallel-syncs themaster 2

# Generated by CONFIG REWRITE
dir "/home/bob/app/sentinel-test/slave1"
sentinel config-epoch themaster 0
sentinel leader-epoch themaster 322
sentinel known-slave themaster 10.75.196.216 7001
sentinel known-slave themaster 10.75.196.216 7002
sentinel known-sentinel themaster 10.75.196.216 26381 8497ee90c1e4525c0f957407fefa77427f427e0d
sentinel known-sentinel themaster 10.75.196.216 26379 bdddadb6e825065398be0bae214891d7ccbd6e2a
sentinel current-epoch 322

哨兵3:
port 26381
protected-mode no

sentinel myid 8497ee90c1e4525c0f957407fefa77427f427e0d
sentinel monitor themaster 10.75.196.216 7000 2
sentinel down-after-milliseconds themaster 3000
sentinel failover-timeout themaster 5000
sentinel parallel-syncs themaster 2

# Generated by CONFIG REWRITE
dir "/home/bob/app/sentinel-test/slave2"
sentinel config-epoch themaster 0
sentinel leader-epoch themaster 322
sentinel known-slave themaster 10.75.196.216 7001
sentinel known-slave themaster 10.75.196.216 7002
sentinel known-sentinel themaster 10.75.196.216 26379 bdddadb6e825065398be0bae214891d7ccbd6e2a
sentinel known-sentinel themaster 10.75.196.216 26380 181fb84351d6b96e0120bfa68331738ef111c49f
sentinel current-epoch 322

主控制台日志:
caching - Redis哨兵故障转移无法正常工作-LMLPHP
哨兵1控制台日志:
caching - Redis哨兵故障转移无法正常工作-LMLPHP
哨兵1信息命令结果:
caching - Redis哨兵故障转移无法正常工作-LMLPHP
主人倒下后的哨兵1日志:
caching - Redis哨兵故障转移无法正常工作-LMLPHP
我的配置怎么了?
提前谢谢。

最佳答案

好的,如果您注意到sentinel日志,当它启动时,甚至在主实例停止工作之前,它会说有两个从服务器关闭:
caching - Redis哨兵故障转移无法正常工作-LMLPHP
可能这就是为什么没有一个从机足够好成为新的主机,我们看到-主机关闭后,在sentinel日志中故障转移中止没有好的从机错误。
所以,因为我记得我犯了以下错误:
(错误)只读不能对只读从机进行写操作
当我试图通过redis cli将密钥设置到从属节点时,我决定在从属配置文件(这两个文件)中插入以下行来修复这个只读错误:
从只读否
通过修复此部分并重新启动所有程序,哨兵日志中不再出现+sdown slave错误,也解决了主要问题。哨兵现在可以切换到一个新的从机实例在主从事件。
正如我在互联网上看到的,另一个人有一个类似的+sdown问题,但在他的情况下,问题是身份验证。
我感谢所有人分享他们的知识和经验。希望这能帮助别人。

10-07 17:33