docker 安装 redis 6.0.8 cluster 实战 (3主3从) 动态缩容

这里将上篇博客扩容的4主4从 缩容为3主3从

1. 检查集群状态
redis-cli --pass admin123 --cluster check 你的ip:16379
并且记录 16385, 16386 的ID

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.19.6.128:16379 (ff3488c6...) -> 1 keys | 4096 slots | 1 slaves.
172.19.6.128:16385 (3f081a67...) -> 1 keys | 4096 slots | 1 slaves.
172.19.6.128:16381 (7de70297...) -> 1 keys | 4096 slots | 1 slaves.
172.19.6.128:16380 (30dd349f...) -> 1 keys | 4096 slots | 1 slaves.
[OK] 4 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 172.19.6.128:16379)
M: ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
S: a2bd918b2e2072ab238bc1937710ea7ed05a7c03 172.19.6.128:16386
   slots: (0 slots) slave
   replicates 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
M: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 172.19.6.128:16385
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
   1 additional replica(s)
S: 001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383
   slots: (0 slots) slave
   replicates ff3488c654a8006784faa35b8a181a567ec2436a
S: e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384
   slots: (0 slots) slave
   replicates 30dd349f6405017a5063d25b9e1d61f39db4c3dc
M: 7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
M: 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382
   slots: (0 slots) slave
   replicates 7de702973b5d649d206d4ba48c772155f6088657
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
root@OrionEcsServer:/data# 

2. 清除 slave 节点
redis-cli --pass admin123 --cluster del-node 你的ip:16386 刚刚记录的slaveId

root@OrionEcsServer:/data# redis-cli --pass admin123 --cluster del-node 172.19.6.128:16386 a2bd918b2e2072ab238bc1937710ea7ed05a7c03
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Removing node a2bd918b2e2072ab238bc1937710ea7ed05a7c03 from cluster 172.19.6.128:16386
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.
root@OrionEcsServer:/data# 

3. 重新分配 slot
redis-cli --pass admin123 --cluster reshard 你的ip:16379
第一次输入: 需要移动的槽数 4096
第二次输入: 接收的 nodeId (16379) ff3488c654a8006784faa35b8a181a567ec2436a
第三次输入: 移动的 nodeId (16385) 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
第四次输入: 结束 done
第五次输入: yes 

这里我图方便, 将4096个槽全部分配给了16379, 其实这里可以多次执行重新分配的操作

t@OrionEcsServer:/data# redis-cli --pass admin123 --cluster reshard 172.19.6.128:16379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 172.19.6.128:16379)
M: ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 172.19.6.128:16385
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: 001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383
   slots: (0 slots) slave
   replicates ff3488c654a8006784faa35b8a181a567ec2436a
S: e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384
   slots: (0 slots) slave
   replicates 30dd349f6405017a5063d25b9e1d61f39db4c3dc
M: 7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
M: 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382
   slots: (0 slots) slave
   replicates 7de702973b5d649d206d4ba48c772155f6088657
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID? ff3488c654a8006784faa35b8a181a567ec2436a
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
Source node #1: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
Source node #2: done

Ready to move 4096 slots.
  Source nodes:
    M: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 172.19.6.128:16385
       slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
  Destination node:
    M: ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379
       slots:[1365-5460] (4096 slots) master
       1 additional replica(s)
  Resharding plan:
    Moving slot 0 from 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
    Moving slot 1 from 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
    Moving slot 2 from 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
    ...
    Moving slot 12286 from 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
    Moving slot 12287 from 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot 0 from 172.19.6.128:16385 to 172.19.6.128:16379: 
Moving slot 1 from 172.19.6.128:16385 to 172.19.6.128:16379: 
Moving slot 2 from 172.19.6.128:16385 to 172.19.6.128:16379: 
...
Moving slot 12287 from 172.19.6.128:16385 to 172.19.6.128:16379: 
root@OrionEcsServer:/data# 

4. 清除 master 节点
redis-cli --pass admin123 --cluster del-node 你的ip16385 刚刚记录的masterId

root@OrionEcsServer:/data# redis-cli --pass admin123 --cluster del-node 172.19.6.128:16385 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Removing node 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 from cluster 172.19.6.128:16385
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.
root@OrionEcsServer:/data# 

5. 检查集群状态

redis-cli --pass admin123 --cluster check 你的ip:16379

这里可以发现已经变成了3主3从

root@OrionEcsServer:/data# redis-cli --pass admin123 --cluster check 172.19.6.128:16379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.19.6.128:16379 (ff3488c6...) -> 2 keys | 8192 slots | 1 slaves.
172.19.6.128:16381 (7de70297...) -> 1 keys | 4096 slots | 1 slaves.
172.19.6.128:16380 (30dd349f...) -> 1 keys | 4096 slots | 1 slaves.
[OK] 4 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 172.19.6.128:16379)
M: ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379
   slots:[0-6826],[10923-12287] (8192 slots) master
   1 additional replica(s)
S: 001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383
   slots: (0 slots) slave
   replicates ff3488c654a8006784faa35b8a181a567ec2436a
S: e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384
   slots: (0 slots) slave
   replicates 30dd349f6405017a5063d25b9e1d61f39db4c3dc
M: 7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
M: 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382
   slots: (0 slots) slave
   replicates 7de702973b5d649d206d4ba48c772155f6088657
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
root@OrionEcsServer:/data# 

6. 查看集群状态
redis-cli -p 16379 -c --pass admin123
cluster info
cluster nodes  

oot@OrionEcsServer:/data# redis-cli -p 16379 -c --pass admin123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:16379> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:8
cluster_my_epoch:8
cluster_stats_messages_ping_sent:3921
cluster_stats_messages_pong_sent:3915
cluster_stats_messages_update_sent:4
cluster_stats_messages_sent:7840
cluster_stats_messages_ping_received:3909
cluster_stats_messages_pong_received:3921
cluster_stats_messages_meet_received:6
cluster_stats_messages_received:7836
127.0.0.1:16379> cluster nodes
ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379@26379 myself,master - 0 1670163237000 8 connected 0-6826 10923-12287
001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383@26383 slave ff3488c654a8006784faa35b8a181a567ec2436a 0 1670163236781 8 connected
e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384@26384 slave 30dd349f6405017a5063d25b9e1d61f39db4c3dc 0 1670163237784 2 connected
7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381@26381 master - 0 1670163235000 3 connected 12288-16383
30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380@26380 master - 0 1670163234778 2 connected 6827-10922
b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382@26382 slave 7de702973b5d649d206d4ba48c772155f6088657 0 1670163235781 3 connected
127.0.0.1:16379> 

7. 测试
        set a 1
        set b 2
        set c 3

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值