8.7 Redis集群之故障自动转移

1.集群节点信息
在这里插入图片描述
6372是6375的从节点。

2.挂掉6375,观察6372是否会晋升为主节点继续提供服务

ps -ef | grep redis
kill -9 5928

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
从上图中可以看到,6372晋升为主节点,并正常提供服务。

3.6372节点日志变化

#主节点下线
22398:S 01 Feb 2023 22:50:04.149 # Connection with master lost.
22398:S 01 Feb 2023 22:50:04.149 * Caching the disconnected master state.
#重连主节点start(超时时间在配置文件中)
22398:S 01 Feb 2023 22:50:04.149 * Reconnecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:04.149 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:04.149 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:04.779 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:04.779 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:04.779 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:05.784 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:05.784 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:05.784 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:06.789 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:06.789 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:06.789 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:07.794 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:07.794 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:07.794 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:08.799 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:08.799 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:08.799 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:09.804 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:09.804 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:09.805 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:10.809 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:10.809 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:10.810 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:11.814 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:11.814 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:11.815 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:12.820 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:12.820 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:12.820 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:13.825 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:13.825 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:13.825 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:14.830 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:14.830 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:14.831 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:15.836 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:15.836 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:15.838 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:16.842 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:16.842 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:16.842 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:17.847 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:17.847 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:17.847 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:18.852 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:18.852 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:18.852 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:19.857 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:19.858 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:19.858 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:20.863 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:20.863 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:20.865 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:21.871 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:21.871 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:21.871 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:22.876 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:22.876 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:22.876 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:23.880 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:23.880 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:23.881 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:24.885 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:24.885 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:24.886 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:25.890 * FAIL message received from b8010c02266eb3a4fb23e2724b2a334f34722e30 about e99c4338f171bd3ee45d7597aa4336ff2a5dc41f
22398:S 01 Feb 2023 22:50:25.890 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:25.891 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:25.891 # Start of election delayed for 985 milliseconds (rank #0, offset 49342).
22398:S 01 Feb 2023 22:50:25.891 # Cluster state changed: fail
22398:S 01 Feb 2023 22:50:25.891 # Error condition on socket for SYNC: Connection refused
22398:S 01 Feb 2023 22:50:26.896 * Connecting to MASTER 121.4.191.137:6375
22398:S 01 Feb 2023 22:50:26.896 * MASTER <-> REPLICA sync started
22398:S 01 Feb 2023 22:50:26.896 # Starting a failover election for epoch 9.
22398:S 01 Feb 2023 22:50:26.900 # Error condition on socket for SYNC: Connection refused
#重连主节点end
#从节点成为新的master
22398:S 01 Feb 2023 22:50:26.904 # Failover election won: I'm the new master.
22398:S 01 Feb 2023 22:50:26.904 # configEpoch set to 9 after successful failover
22398:M 01 Feb 2023 22:50:26.904 * Discarding previously cached master state.
22398:M 01 Feb 2023 22:50:26.904 # Setting secondary replication ID to db262f1317558dc051af4f52f0e50faa73bff022, valid up to offset: 49343. New replication ID is d24235ee6476b3ef0d675f45a63656cd1a1155a7
22398:M 01 Feb 2023 22:50:26.904 # Cluster state changed: ok

4.重启6375节点,观察集群节点信息

cd /usr/local/redis/src
redis-server  /usr/local/redis/cluster/conf/redis-6375.conf
ps -ef | grep redis

在这里插入图片描述
在这里插入图片描述
可以看到,6375成为6372的从节点。

5.6375节点日志变化

30013:C 01 Feb 2023 23:09:45.332 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
30013:C 01 Feb 2023 23:09:45.332 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=30013, just started
30013:C 01 Feb 2023 23:09:45.332 # Configuration loaded
30013:M 01 Feb 2023 23:09:45.333 * monotonic clock: POSIX clock_gettime
30013:M 01 Feb 2023 23:09:45.334 * Node configuration loaded, I'm e99c4338f171bd3ee45d7597aa4336ff2a5dc41f
30013:M 01 Feb 2023 23:09:45.334 * Running mode=cluster, port=6375.
30013:M 01 Feb 2023 23:09:45.334 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
30013:M 01 Feb 2023 23:09:45.334 # Server initialized
30013:M 01 Feb 2023 23:09:45.334 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
30013:M 01 Feb 2023 23:09:45.335 * DB loaded from append only file: 0.000 seconds
30013:M 01 Feb 2023 23:09:45.335 * Ready to accept connections
30013:M 01 Feb 2023 23:09:45.336 # Configuration change detected. Reconfiguring myself as a replica of 58ba15be743b298766cafea04646ea9bfbfe3389
30013:S 01 Feb 2023 23:09:45.336 * Before turning into a replica, using my own master parameters to synthesize a cached master: I may be able to synchronize with the new master with just a partial transfer.
#连接到主节点6372
30013:S 01 Feb 2023 23:09:45.336 * Connecting to MASTER 121.4.211.73:6372
30013:S 01 Feb 2023 23:09:45.336 * MASTER <-> REPLICA sync started
30013:S 01 Feb 2023 23:09:45.336 # Cluster state changed: ok
30013:S 01 Feb 2023 23:09:45.340 * Non blocking connect for SYNC fired the event.
30013:S 01 Feb 2023 23:09:45.340 * Master replied to PING, replication can continue...
30013:S 01 Feb 2023 23:09:45.341 * Trying a partial resynchronization (request ffb52f67e20e4d272cc09de8318d5d834a93293c:1).
30013:S 01 Feb 2023 23:09:45.341 * Full resync from master: d24235ee6476b3ef0d675f45a63656cd1a1155a7:49342
30013:S 01 Feb 2023 23:09:45.341 * Discarding previously cached master state.
30013:S 01 Feb 2023 23:09:45.365 * MASTER <-> REPLICA sync: receiving 200 bytes from master to disk
30013:S 01 Feb 2023 23:09:45.365 * MASTER <-> REPLICA sync: Flushing old data
30013:S 01 Feb 2023 23:09:45.365 * MASTER <-> REPLICA sync: Loading DB in memory
30013:S 01 Feb 2023 23:09:45.371 * Loading RDB produced by version 6.2.6
30013:S 01 Feb 2023 23:09:45.371 * RDB age 0 seconds
30013:S 01 Feb 2023 23:09:45.371 * RDB memory usage when created 2.57 Mb
30013:S 01 Feb 2023 23:09:45.372 # Done loading RDB, keys loaded: 1, keys expired: 0.
#完成复制
30013:S 01 Feb 2023 23:09:45.372 * MASTER <-> REPLICA sync: Finished with success
30013:S 01 Feb 2023 23:09:45.372 * Background append only file rewriting started by pid 30019
30013:S 01 Feb 2023 23:09:45.397 * AOF rewrite child asks to stop sending diffs.
30019:C 01 Feb 2023 23:09:45.397 * Parent agreed to stop sending diffs. Finalizing AOF...
30019:C 01 Feb 2023 23:09:45.397 * Concatenating 0.00 MB of AOF diff received from parent.
30019:C 01 Feb 2023 23:09:45.398 * SYNC append only file rewrite performed
30019:C 01 Feb 2023 23:09:45.398 * AOF rewrite: 0 MB of memory used by copy-on-write
30013:S 01 Feb 2023 23:09:45.436 * Background AOF rewrite terminated with success
30013:S 01 Feb 2023 23:09:45.436 * Residual parent diff successfully flushed to the rewritten AOF (0.00 MB)
30013:S 01 Feb 2023 23:09:45.436 * Background AOF rewrite finished successfully
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值