首页 > 解决方案 > Redis 节点不会进入 MASTER 模式

问题描述

我有一个简单的 redis 部署 MASTER、SLAVE 和 2 SENTINEL 在 docker swarm 上运行。我运行堆栈,所有服务都出现了。redis-master 以 MASTER 启动,我将其杀死以测试 SENTINEL 和 SLAVE 恢复。redis-master 然后恢复并成为一个新的 SLAVE。如果我 ecex 进入它并运行 SLAVEOF NO ONE,则会发生以下情况:

1:M 31 Oct 2019 06:28:32.741 * MASTER MODE enabled (user request from 'id=3907 addr=127.0.0.1:39302 fd=36 name= age=0 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=34 qbuf-free=32734 obl=0 oll=0 omem=0 events=r cmd=slaveof')
1:S 31 Oct 2019 06:28:43.060 * Before turning into a replica, using my master parameters to synthesize a cached master: I may be able to synchronize with the new master with just a partial transfer.
1:S 31 Oct 2019 06:28:43.060 * REPLICAOF 10.0.21.49:6379 enabled (user request from 'id=1085 addr=10.0.21.54:34360 fd=16 name=sentinel-592f3b97-cmd age=945 idle=0 flags=x db=0 sub=0 psub=0 multi=3 qbuf=150 qbuf-free=32618 obl=36 oll=0 omem=0 events=r cmd=exec')
1:S 31 Oct 2019 06:28:43.701 * Connecting to MASTER 10.0.21.49:6379
1:S 31 Oct 2019 06:28:43.702 * MASTER <-> REPLICA sync started
1:S 31 Oct 2019 06:28:43.702 * Non blocking connect for SYNC fired the event.
1:S 31 Oct 2019 06:28:43.702 * Master replied to PING, replication can continue...
1:S 31 Oct 2019 06:28:43.703 * Trying a partial resynchronization (request a056665afb95a1e3a4227ae7fcb1c9b2e2f3b222:244418).
1:S 31 Oct 2019 06:28:43.703 * Full resync from master: adde2c9daee4fa1e62d3494d74d08dfb7110c798:241829
1:S 31 Oct 2019 06:28:43.703 * Discarding previously cached master state.
1:S 31 Oct 2019 06:28:43.715 * MASTER <-> REPLICA sync: receiving 2229 bytes from master
1:S 31 Oct 2019 06:28:43.715 * MASTER <-> REPLICA sync: Flushing old data
1:S 31 Oct 2019 06:28:43.715 * MASTER <-> REPLICA sync: Loading DB in memory
1:S 31 Oct 2019 06:28:43.715 * MASTER <-> REPLICA sync: Finished with success

大师模式启动,但随后被 REPLICAOF 接管!如何强制 redis-master 始终是 MASTER?

标签: redisredis-cli

解决方案


是的,我认为这是有道理的。

哨兵会永远记住谁加入了主从组。

当您手动设置当前从属主机时,哨兵不知道您是否故意这样做,或者发生了网络部分。所以哨兵会做一个convert-to-slave来避免两个主人在一个组中存在。(又名,裂脑

从组中删除节点

检查文档,简而言之,您需要发送SENTINEL RESET mastername所有哨兵,让他们忘记丢失的节点。然后将丢失的节点作为master启动,它不会加入sentinel的组。

使前一个(失败的)主节点保持为主节点。

在丢失的master作为slave回来后,你可以做一个SENTINEL failover <master name>,sentinels会做一个failover并切换master和slave。但我认为当节点超过 3 个时,您不能指定主节点。


推荐阅读