【架构】Docker实现集群主从缩容【案例4/4】

实现集群主从缩容【4/4】

接上一节,在当前机器为4主4从的架构上,减缩容量为3主3从架构。即实现删除6387和6388.

示意图如下:

第一步:查看集群情况(第一次)

python 复制代码
redis-cli --cluster check 127.0.0.1:6387
root@localhost:/data# redis-cli --cluster check 127.0.0.1:6387
127.0.0.1:6387 (bf73145e...) -> 1 keys | 4096 slots | 1 slaves.
12.114.161.16:6381 (6e961a47...) -> 1 keys | 4096 slots | 1 slaves.
12.114.161.16:6383 (78ac7be1...) -> 1 keys | 4096 slots | 1 slaves.
12.114.161.16:6382 (f097fec9...) -> 1 keys | 4096 slots | 1 slaves.
[OK] 4 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:6387)
M: bf73145e2eaaaa08084c9c2dad0d8c757faa48e1 127.0.0.1:6387
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
   1 additional replica(s)
S: 4ed46e0368698cd9d5af2ee84631c878b8ebc4d0 12.114.161.16:6386
   slots: (0 slots) slave
   replicates 6e961a4765b555189708bebb69badf7dfad25cd5
S: 664e456ae7d5cf27ea6583ba2f437dac11d4e767 12.114.161.16:6388
   slots: (0 slots) slave
   replicates bf73145e2eaaaa08084c9c2dad0d8c757faa48e1
S: 9bc2417a9cd6545ef2445eb4aa0610d586acd73b 12.114.161.16:6385
   slots: (0 slots) slave
   replicates 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2
M: 6e961a4765b555189708bebb69badf7dfad25cd5 12.114.161.16:6381
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
S: 0e34147ce2544cd90f5cce78d5493ae9e8625dfe 12.114.161.16:6384
   slots: (0 slots) slave
   replicates f097fec937f54d147d316c1c62e26cb67c9fd059
M: 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2 12.114.161.16:6383
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
M: f097fec937f54d147d316c1c62e26cb67c9fd059 12.114.161.16:6382
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

第二步:删除从主机(6388),删除参数【--cluster del-node

python 复制代码
redis-cli --cluster del-node 12.114.161.16:6388 664e456ae7d5cf27ea6583ba2f437dac11d4e767
root@localhost:/data# redis-cli --cluster del-node 12.114.161.16:6388 664e456ae7d5cf27ea6583ba2f437dac11d4e767
>>> Removing node 664e456ae7d5cf27ea6583ba2f437dac11d4e767 from cluster 12.114.161.16:6388
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.

第三步:查看集群情况(第二次)

python 复制代码
redis-cli --cluster check 127.0.0.1:6387
略。。。

第四步:将该主机的槽位分给6381主机【--cluster reshard

python 复制代码
redis-cli --cluster reshard 12.114.161.16:6381
root@localhost:/data# redis-cli --cluster reshard 12.114.161.16:6381
>>> Performing Cluster Check (using node 12.114.161.16:6381)
M: 6e961a4765b555189708bebb69badf7dfad25cd5 12.114.161.16:6381
   slots:[0-6826],[10923-12287] (8192 slots) master
   1 additional replica(s)
S: 4ed46e0368698cd9d5af2ee84631c878b8ebc4d0 12.114.161.16:6386
   slots: (0 slots) slave
   replicates 6e961a4765b555189708bebb69badf7dfad25cd5
M: bf73145e2eaaaa08084c9c2dad0d8c757faa48e1 12.114.161.16:6387
   slots: (0 slots) master
S: 9bc2417a9cd6545ef2445eb4aa0610d586acd73b 12.114.161.16:6385
   slots: (0 slots) slave
   replicates 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2
S: 0e34147ce2544cd90f5cce78d5493ae9e8625dfe 12.114.161.16:6384
   slots: (0 slots) slave
   replicates f097fec937f54d147d316c1c62e26cb67c9fd059
M: f097fec937f54d147d316c1c62e26cb67c9fd059 12.114.161.16:6382
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
M: 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2 12.114.161.16:6383
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
[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? 6e961a4765b555189708bebb69badf7dfad25cd5     # 分给哪一台master 主机ID
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: bf73145e2eaaaa08084c9c2dad0d8c757faa48e1             # 从哪一台主机移除的槽位 主机ID
Source node #2: done             # 输入done即可 ,后面提示 直接输入'yes'即可
...
....

第五步:查看集群情况(第三次),确定需要移除主机的槽位数为0

python 复制代码
redis-cli --cluster check 127.0.0.1:6387
root@localhost:/data# redis-cli --cluster check 12.114.161.16:6381  
12.114.161.16:6381 (6e961a47...) -> 2 keys | 8192 slots | 1 slaves.      # 此处显示加上移除来的4096个槽位,总共有8192个槽位。转移成功!
12.114.161.16:6387 (bf73145e...) -> 0 keys | 0 slots | 0 slaves.         # 此次显示原来4096个槽位已经移除,显示为 0
12.114.161.16:6382 (f097fec9...) -> 1 keys | 4096 slots | 1 slaves.
12.114.161.16:6383 (78ac7be1...) -> 1 keys | 4096 slots | 1 slaves.
[OK] 4 keys in 4 masters.                                                  # 显示总共4台master主机
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 12.114.161.16:6381)
M: 6e961a4765b555189708bebb69badf7dfad25cd5 12.114.161.16:6381
   slots:[0-6826],[10923-12287] (8192 slots) master
   1 additional replica(s)
S: 4ed46e0368698cd9d5af2ee84631c878b8ebc4d0 12.114.161.16:6386
   slots: (0 slots) slave
   replicates 6e961a4765b555189708bebb69badf7dfad25cd5
M: bf73145e2eaaaa08084c9c2dad0d8c757faa48e1 12.114.161.16:6387
   slots: (0 slots) master                                                 # 此次显示原来Master主机的 4096个槽位已经移除,显示为 0              
S: 9bc2417a9cd6545ef2445eb4aa0610d586acd73b 12.114.161.16:6385
   slots: (0 slots) slave
   replicates 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2
S: 0e34147ce2544cd90f5cce78d5493ae9e8625dfe 12.114.161.16:6384
   slots: (0 slots) slave
   replicates f097fec937f54d147d316c1c62e26cb67c9fd059
M: f097fec937f54d147d316c1c62e26cb67c9fd059 12.114.161.16:6382
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
M: 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2 12.114.161.16:6383
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

根据上面的数据显示,槽位已经转移成功!

注意:如果想将4096个槽位平均分给另外三台master主机,那么需要重复该操作三次,分别输入不同的目标ID即可!

第六步:删除master主机(6387),删除参数【--cluster del-node

python 复制代码
redis-cli --cluster del-node 12.114.161.16:6387 bf73145e2eaaaa08084c9c2dad0d8c757faa48e1
root@localhost:/data# redis-cli --cluster del-node 12.114.161.16:6381 bf73145e2eaaaa08084c9c2dad0d8c757faa48e1
>>> Removing node bf73145e2eaaaa08084c9c2dad0d8c757faa48e1 from cluster 12.114.161.16:6381
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.

第七步:查看最终的集群情况(第四次)

python 复制代码
redis-cli --cluster check 127.0.0.1:6387
root@localhost:/data# 
root@localhost:/data# 
root@localhost:/data# redis-cli --cluster check 12.114.161.16:6381                                            
12.114.161.16:6381 (6e961a47...) -> 2 keys | 8192 slots | 1 slaves.       # 该列表不在显示6387端口的master主机了
12.114.161.16:6382 (f097fec9...) -> 1 keys | 4096 slots | 1 slaves.
12.114.161.16:6383 (78ac7be1...) -> 1 keys | 4096 slots | 1 slaves.
[OK] 4 keys in 3 masters.                                                   # 此次仅仅剩下3台Master主机
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 12.114.161.16:6381)
M: 6e961a4765b555189708bebb69badf7dfad25cd5 12.114.161.16:6381
   slots:[0-6826],[10923-12287] (8192 slots) master
   1 additional replica(s)
S: 4ed46e0368698cd9d5af2ee84631c878b8ebc4d0 12.114.161.16:6386
   slots: (0 slots) slave
   replicates 6e961a4765b555189708bebb69badf7dfad25cd5
S: 9bc2417a9cd6545ef2445eb4aa0610d586acd73b 12.114.161.16:6385
   slots: (0 slots) slave
   replicates 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2
S: 0e34147ce2544cd90f5cce78d5493ae9e8625dfe 12.114.161.16:6384
   slots: (0 slots) slave
   replicates f097fec937f54d147d316c1c62e26cb67c9fd059
M: f097fec937f54d147d316c1c62e26cb67c9fd059 12.114.161.16:6382
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
M: 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2 12.114.161.16:6383
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

至此,成功将原来的"4主4从架构",缩容成"3主3从架构"!

相关推荐
全能全知者5 分钟前
docker快速安装与配置mongoDB
mongodb·docker·容器
九圣残炎15 分钟前
【从零开始的LeetCode-算法】1456. 定长子串中元音的最大数目
java·算法·leetcode
wclass-zhengge17 分钟前
Netty篇(入门编程)
java·linux·服务器
Re.不晚44 分钟前
Java入门15——抽象类
java·开发语言·学习·算法·intellij-idea
雷神乐乐1 小时前
Maven学习——创建Maven的Java和Web工程,并运行在Tomcat上
java·maven
码农派大星。1 小时前
Spring Boot 配置文件
java·spring boot·后端
顾北川_野1 小时前
Android 手机设备的OEM-unlock解锁 和 adb push文件
android·java
江深竹静,一苇以航1 小时前
springboot3项目整合Mybatis-plus启动项目报错:Invalid bean definition with name ‘xxxMapper‘
java·spring boot
confiself1 小时前
大模型系列——LLAMA-O1 复刻代码解读
java·开发语言
Wlq04151 小时前
J2EE平台
java·java-ee