redis cluster如何添加和删除节点?


redis cluster如何增加和删除节点?

背景说明

由于虚拟环境有限,目前所采用的集群方案是在 3 台机器去搭建 6 个 redis 实例的 redis cluster(每台两个)。

使用命令 redis-cli -h 10.0.0.4 -p 7001 cluster nodes 查看当前集群节点

在这里插入图片描述

添加节点

添加master节点

配置并启动即将添加的节点,具体操作参考简单搭建redis cluster集群

第一步:使用命令 redis-cli --cluster add-node 10.0.0.7:7007 10.0.0.4:7001 添加节点;

前面的 ip:port 为将要添加的节点,后面的 ip:port 表示集群中的任意一个节点。

在这里插入图片描述

第二步:使用命令 redis-cli --cluster reshard 10.0.0.7:7007 分配 slots。

执行命令 redis-cli --cluster reshard 10.0.0.7:7007 时出现的询问:
How many slots do you want to move (from 1 to 16384)?:表示需要移动槽的数量。填写自己的需要即可。
What is the receiving node ID?:表示:那个 id 来接收它。即新的 7007 的 id。
Source node #1:从填写的那个节点 id 上移动散列插槽。如果需要平均节点插槽,那么每个主节点的 id 都写上或者写 all。
Do you want to proceed with the proposed reshard plan (yes/no)?:确定要移动这些槽的计划吗?输入 yes 或者 no。

[root@mq4 init.d]# redis-cli --cluster reshard 10.0.0.7:7007
>>> Performing Cluster Check (using node 10.0.0.7:7007)
M: f1f7185e3f0a1096ad16b598005875e1b2d306cc 10.0.0.7:7007
   slots: (0 slots) master
   1 additional replica(s)
S: 15df8829b8e756ce76ae1c2b3d879193a758348a 10.0.0.7:7008
   slots: (0 slots) slave
   replicates f1f7185e3f0a1096ad16b598005875e1b2d306cc
M: 58869cf6dee60706154a5a3461c4687922e6ea60 10.0.0.5:7003
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 1a7a4d4168b0e3203f6c6c1e0a35351760f1bacf 10.0.0.4:7001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 32a1ec21e51934856a97efd8ce4bfc8ff90619d2 10.0.0.4:7002
   slots: (0 slots) slave
   replicates 5f8f0c5c6b71615cc837cb1efe2997a35de45623
M: 5f8f0c5c6b71615cc837cb1efe2997a35de45623 10.0.0.6:7005
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 6959f6d61974895474c800c4c46f704ad4857264 10.0.0.5:7004
   slots: (0 slots) slave
   replicates 1a7a4d4168b0e3203f6c6c1e0a35351760f1bacf
S: 0ea5f18383cfa1fb70d4af093cd1946fc0e2aff6 10.0.0.6:7006
   slots: (0 slots) slave
   replicates 58869cf6dee60706154a5a3461c4687922e6ea60
[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? f1f7185e3f0a1096ad16b598005875e1b2d306cc
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: all

Ready to move 4096 slots.
  Source nodes:
    M: 58869cf6dee60706154a5a3461c4687922e6ea60 10.0.0.5:7003
       slots:[5461-10922] (5462 slots) master
       1 additional replica(s)
    M: 1a7a4d4168b0e3203f6c6c1e0a35351760f1bacf 10.0.0.4:7001
       slots:[0-5460] (5461 slots) master
       1 additional replica(s)
    M: 5f8f0c5c6b71615cc837cb1efe2997a35de45623 10.0.0.6:7005
       slots:[10923-16383] (5461 slots) master
       1 additional replica(s)
  Destination node:
    M: f1f7185e3f0a1096ad16b598005875e1b2d306cc 10.0.0.7:7007
       slots: (0 slots) master
       1 additional replica(s)
  Resharding plan:
    Moving slot 5461 from 58869cf6dee60706154a5a3461c4687922e6ea60
    Moving slot 5462 from 58869cf6dee60706154a5a3461c4687922e6ea60
    Moving slot 5463 from 58869cf6dee60706154a5a3461c4687922e6ea60
    Moving slot 5464 from 58869cf6dee60706154a5a3461c4687922e6ea60
    Moving slot 5465 from 58869cf6dee60706154a5a3461c4687922e6ea60
    Moving slot 5466 from 58869cf6dee60706154a5a3461c4687922e6ea60
    Moving slot 5467 from 58869cf6dee60706154a5a3461c4687922e6ea60
    Moving slot 5468 from 58869cf6dee60706154a5a3461c4687922e6ea60
......
Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot 5461 from 10.0.0.5:7003 to 10.0.0.7:7007:
Moving slot 5462 from 10.0.0.5:7003 to 10.0.0.7:7007:
Moving slot 5463 from 10.0.0.5:7003 to 10.0.0.7:7007:
Moving slot 5464 from 10.0.0.5:7003 to 10.0.0.7:7007:
Moving slot 5465 from 10.0.0.5:7003 to 10.0.0.7:7007:
Moving slot 5466 from 10.0.0.5:7003 to 10.0.0.7:7007:
Moving slot 5467 from 10.0.0.5:7003 to 10.0.0.7:7007:
Moving slot 5468 from 10.0.0.5:7003 to 10.0.0.7:7007:
......

查看集群节点

在这里插入图片描述

添加slave节点

相比于添加 master 节点,添加 slave 节点则不需要分配 slot,只需执行命令 redis-cli --cluster add-node 10.0.0.7:7008 10.0.0.4:7001 --cluster-s lave f1f7185e3f0a1096ad16b598005875e1b2d306cc 即可。

在这里插入图片描述

删除节点

删除master节点

因为 master 节点是分配了 slot 的,所以删除节点之前需要把 solt 移动到其他 master 节点上去,也就行执行 reshard 操作,否则数据会丢失。

然后执行命令 redis-cli --cluster del-node ip:prot 删除节点。

删除slave节点

相比于删除 master 节点,删除 slave 节点直接删除即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

久违の欢喜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值