redis cluster 现有分片添加副本节点
6001(M)->7002(S)
6002(M)->7003(S)
6003(M)->7001(S)
6004(M)->7004(S)
6001(M)->7002(S)
6002(M)->7003(S)
6003(M)->7001(S)
6004(M)->7004(S)->8004(S)
mkdir /data/redis-8004
[root@centos8-arm64-sql redis]# cp redis_7004.conf redis_8004.conf
[root@centos8-arm64-sql redis]# sed -i 's/7004/8004/g' redis_8004.conf
[root@centos8-arm64-sql redis]# redis-server /etc/redis/redis_8004.conf
[root@centos8-arm64-sql redis]# redis-cli -p 8004 -h 172.16.105.131 -a s3cureDis -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.16.105.131:8004> cluster nodes
7e7f959ccd8a6578c0e3d0d8d6a1a3da80c48ad1 :8004@18004 myself,master - 0 0 0 connected
有两种方法可以将8004加入到现有集群,并作为6004的副本
https://redis.io/docs/management/scaling/
方法(1)
172.16.105.131:8004是新加入的副本节点
172.16.105.131:6001是集群的任意一个节点
--cluster-slave表示新加入的节点是slave角色,默认是master
--cluster-master-id d2e5f8c7ab30286b853936049d907be423224318该ID为6004的节点ID,表示新加入的副本节点与6004为master进行同步
redis-cli --cluster add-node 172.16.105.131:8004 172.16.105.131:6001 --cluster-slave --cluster-master-id d2e5f8c7ab30286b853936049d907be423224318 -a s3cureDis
方法(2)
加入节点8004作为6004的副本
redis-cli --cluster add-node 172.16.105.131:8004 172.16.105.131:6001 -a s3cureDis
修改8004的复制关系
redis-cli -p 8004 -h 172.16.105.131 -a s3cureDis
cluster help
cluster replicate d2e5f8c7ab30286b853936049d907be423224318 --6004的节点ID
redis-cli --cluster check 127.0.0.1:8004 -a s3cureDis
redis-cli --cluster info 127.0.0.1:8004 -a s3cureDis
redis-cli -p 8004 -a s3cureDis -c cluster nodes
redis-cli -p 8004 -a s3cureDis -c keys "*"
[root@centos8-arm64-sql redis]# redis-cli --cluster add-node 172.16.105.131:8004 172.16.105.131:6001 --cluster-slave --cluster-master-id d2e5f8c7ab30286b853936049d907be423224318 -a s3cureDis
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 172.16.105.131:8004 to cluster 172.16.105.131:6001
>>> Performing Cluster Check (using node 172.16.105.131:6001)
M: 706a3c5e616452ac1c1c9f4ade4a58f14855f9a8 172.16.105.131:6001
slots:[1365-5460] (4096 slots) master
1 additional replica(s)
M: d2e5f8c7ab30286b853936049d907be423224318 172.16.105.131:6004
slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
1 additional replica(s)
S: d4969f54675a4e6140689f7db509cf31fdfe33f9 172.16.105.131:7003
slots: (0 slots) slave
replicates 1ae63a25a57d8727cde9539fb565f8b903acb1db
S: 9a1efd9e6c7244b8b3b53788de0ef68c62f28858 172.16.105.131:7002
slots: (0 slots) slave
replicates 706a3c5e616452ac1c1c9f4ade4a58f14855f9a8
M: 1ae63a25a57d8727cde9539fb565f8b903acb1db 172.16.105.131:6002
slots:[6827-10922] (4096 slots) master
1 additional replica(s)
S: 55d8eb520292bf331432cafc3c6912d18177b3e4 172.16.105.131:7001
slots: (0 slots) slave
replicates e5cae5be9ef843baa8397666bb7fdcba884acbb5
M: e5cae5be9ef843baa8397666bb7fdcba884acbb5 172.16.105.131:6003
slots:[12288-16383] (4096 slots) master
1 additional replica(s)
S: 95c700906723ca8b1e3e91775c467e20a34e2941 172.16.105.131:7004
slots: (0 slots) slave
replicates d2e5f8c7ab30286b853936049d907be423224318
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 172.16.105.131:8004 to make it join the cluster.
Waiting for the cluster to join
>>> Configure node as replica of 172.16.105.131:6004.
[OK] New node added correctly.
[root@centos8-arm64-sql redis]# redis-cli -p 7004 -h 172.16.105.131 -a s3cureDis -c cluster nodes
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
d2e5f8c7ab30286b853936049d907be423224318 172.16.105.131:6004@16004 master - 0 1681254282563 25 connected 0-1364 5461-6826 10923-12287
706a3c5e616452ac1c1c9f4ade4a58f14855f9a8 172.16.105.131:6001@16001 master - 0 1681254281000 20 connected 1365-5460
9a1efd9e6c7244b8b3b53788de0ef68c62f28858 172.16.105.131:7002@17002 slave 706a3c5e616452ac1c1c9f4ade4a58f14855f9a8 0 1681254281000 20 connected
e5cae5be9ef843baa8397666bb7fdcba884acbb5 172.16.105.131:6003@16003 master - 0 1681254280000 22 connected 12288-16383
7e7f959ccd8a6578c0e3d0d8d6a1a3da80c48ad1 172.16.105.131:8004@18004 slave d2e5f8c7ab30286b853936049d907be423224318 0 1681254281000 25 connected
d4969f54675a4e6140689f7db509cf31fdfe33f9 172.16.105.131:7003@17003 slave 1ae63a25a57d8727cde9539fb565f8b903acb1db 0 1681254282000 21 connected
55d8eb520292bf331432cafc3c6912d18177b3e4 172.16.105.131:7001@17001 slave e5cae5be9ef843baa8397666bb7fdcba884acbb5 0 1681254283673 22 connected
95c700906723ca8b1e3e91775c467e20a34e2941 172.16.105.131:7004@17004 myself,slave d2e5f8c7ab30286b853936049d907be423224318 0 1681254280000 25 connected
1ae63a25a57d8727cde9539fb565f8b903acb1db 172.16.105.131:6002@16002 master - 0 1681254282664 21 connected 6827-10922
6001(M)->7002(S)
6002(M)->7003(S)
6003(M)->7001(S)
6004(M)->7004(S)->8004(S)
Redis Cluster 现有分片添加副本节点
于 2023-04-26 21:47:52 首次发布