我将部署一个简单的主从redis集群,它有两个服务器: 192.168.0.101, 192.168.0.103
,101是主人。
这是你的名字 sentinel.conf
在103服务器上:
port 26379
bind 192.168.0.103 127.0.0.1
sentinel myid 49f552d5540fdcb8aa60be25208c56b689d3c0b0
sentinel monitor mymaster 192.168.0.101 6379 2
sentinel down-after-milliseconds mymaster 60000
sentinel failover-timeout mymaster 900000
sentinel auth-pass mymaster arsenal
sentinel config-epoch mymaster 0
# Generated by CONFIG REWRITE
dir "/etc/redis"
sentinel leader-epoch mymaster 3
sentinel known-slave mymaster 192.168.0.103 6379
sentinel current-epoch 3
以及103服务器上的redis.conf:
bind 127.0.0.1 ::1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
daemonize yes
supervised no
dbfilename dump.rdb
dir /var/lib/redis
slaveof device1 6379
masterauth arsenal
slave-serve-stale-data yes
slave-read-only yes
slave-priority 100
requirepass arsenal
slave-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
activerehashing yes
aof-rewrite-incremental-fsync yes
我从哨兵开始 192.168.0.103
与 redis-server sentinel.conf --sentinel
```
7951:X 14 Mar 14:19:48.479 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7951:X 14 Mar 14:19:48.479 # Sentinel ID is 49f552d5540fdcb8aa60be25208c56b689d3c0b0
7951:X 14 Mar 14:19:48.479 # +monitor master mymaster 192.168.0.101 6379 quorum 2
7951:X 14 Mar 14:20:48.480 # +sdown slave 192.168.0.103:6379 192.168.0.103 6379 @ mymaster 192.168.0.101 6379
7951:X 14 Mar 14:21:11.577 # +sdown master mymaster 192.168.0.101 6379
我的哨兵呼叫是这样的:
sentinel = Sentinel([('device3', 26379)], password='arsenal')
sentinel.discover_master('mymaster')
MasterNotFoundError: No master found for 'mymaster'
问题是在我尝试停止101上的redis服务器服务后,sentinel无法将103服务器切换为主服务器。
有人知道吗?谢谢。
1条答案
按热度按时间kmynzznz1#
在您的配置中
sentinel monitor mymaster 192.168.0.101 6379 2
,quorum为2,这意味着只有两个或两个以上的sentinel认为master关闭,才能启动故障转移。见redis sentinel doc,只有三个或三个以上的sentinel可以稳定部署,如果只有一个sentinel,就不能选择一个领导者(获得多数票)来启动故障转移。