Redis手动进行主从切换
# Redis手动进行主从切换
# 前言
当redis集群中的一个节点出现故障,需要将主从互换的时候会用到
[dba@redisnode0001 bin]# sudo ./redis-cli -h 127.0.0.1 -p 8001 -c -a xxxxxxxxxxx --cluster check 127.0.0
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:9001 (c1422bc2...) -> 1 keys | 5461 slots | 1 slaves.
172.31.170.16:9002 (87f4cf99...) -> 0 keys | 5462 slots | 1 slaves.
172.31.170.17:9003 (63395075...) -> 1 keys | 5461 slots | 1 slaves.
[OK] 2 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:9001)
M: c1422bc23f702c702a1de872f5a0026238268fa9 127.0.0.1:9001
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: c1000a4985fd5a8c8afd9c8bdaa4d99f137e78eb 172.31.170.15:9003
slots: (0 slots) slave
replicates 633950751a8fc0a18b4a1ad4c5dd90095d4147b0
M: 87f4cf99d533f74532d5b586bbdeabe7dc0df499 172.31.170.16:9002
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
M: 633950751a8fc0a18b4a1ad4c5dd90095d4147b0 172.31.170.17:9003
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 0ca6df3fb57b53700bb2d328696932d3f3fe62c9 172.31.170.15:9001
slots: (0 slots) slave
replicates c1422bc23f702c702a1de872f5a0026238268fa9
S: d6f6aa0a5003a25060e48032544f27044d5445ef 172.31.170.17:9002
slots: (0 slots) slave
replicates 87f4cf99d533f74532d5b586bbdeabe7dc0df499
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
通过check 命令找到与主节点相同ID的从节点,连接上从节点之后执行命令
[dba@redisnode0001 bin]# sudo ./redis-cli -h 172.31.170.15 -p 9001 -c -a xxxxxxxxxxxxx
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.31.170.15:9001> cluster failover
OK
172.31.170.15:9001> cluster nodes
87f4cf99d533f74532d5b586bbdeabe7dc0df499 172.31.170.16:9002@19002 master - 0 1638603378000 2 connected 5461-10922
633950751a8fc0a18b4a1ad4c5dd90095d4147b0 172.31.170.17:9003@19003 master - 0 1638603377000 3 connected 10923-16383
0ca6df3fb57b53700bb2d328696932d3f3fe62c9 172.31.170.15:9001@19001 myself,master - 0 1638603377000 5 connected 0-5460
c1422bc23f702c702a1de872f5a0026238268fa9 172.31.170.16:9001@19001 slave 0ca6df3fb57b53700bb2d328696932d3f3fe62c9 0 1638603378554 5 connected
d6f6aa0a5003a25060e48032544f27044d5445ef 172.31.170.17:9002@19002 slave 87f4cf99d533f74532d5b586bbdeabe7dc0df499 0 1638603378000 2 connected
c1000a4985fd5a8c8afd9c8bdaa4d99f137e78eb 172.31.170.15:9003@19003 slave 633950751a8fc0a18b4a1ad4c5dd90095d4147b0 0 1638603378752 3 connected
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
若无意在主节点上执行的话,会有以下报错
127.0.0.1:8001> cluster failover
(error) ERR You should send CLUSTER FAILOVER to a replica
1
2
2
上次更新: 9/14/2024
- 01
- MongoDB 集群Config Server 复制集的工作原理09-14
- 02
- MongoDB 集群架构介绍09-14