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

2024-01-30 14:12

本文主要是介绍【架构】Docker实现集群主从缩容【案例4/4】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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

接上一节,在当前机器为4主4从的架构上,减缩容量为3主3从架构。即实现删除6387和6388.
示意图如下:
在这里插入图片描述
第一步:查看集群情况(第一次)

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:6387slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master1 additional replica(s)
S: 4ed46e0368698cd9d5af2ee84631c878b8ebc4d0 12.114.161.16:6386slots: (0 slots) slavereplicates 6e961a4765b555189708bebb69badf7dfad25cd5
S: 664e456ae7d5cf27ea6583ba2f437dac11d4e767 12.114.161.16:6388slots: (0 slots) slavereplicates bf73145e2eaaaa08084c9c2dad0d8c757faa48e1
S: 9bc2417a9cd6545ef2445eb4aa0610d586acd73b 12.114.161.16:6385slots: (0 slots) slavereplicates 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2
M: 6e961a4765b555189708bebb69badf7dfad25cd5 12.114.161.16:6381slots:[1365-5460] (4096 slots) master1 additional replica(s)
S: 0e34147ce2544cd90f5cce78d5493ae9e8625dfe 12.114.161.16:6384slots: (0 slots) slavereplicates f097fec937f54d147d316c1c62e26cb67c9fd059
M: 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2 12.114.161.16:6383slots:[12288-16383] (4096 slots) master1 additional replica(s)
M: f097fec937f54d147d316c1c62e26cb67c9fd059 12.114.161.16:6382slots:[6827-10922] (4096 slots) master1 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

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.

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

redis-cli --cluster check 127.0.0.1:6387
略。。。

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

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:6381slots:[0-6826],[10923-12287] (8192 slots) master1 additional replica(s)
S: 4ed46e0368698cd9d5af2ee84631c878b8ebc4d0 12.114.161.16:6386slots: (0 slots) slavereplicates 6e961a4765b555189708bebb69badf7dfad25cd5
M: bf73145e2eaaaa08084c9c2dad0d8c757faa48e1 12.114.161.16:6387slots: (0 slots) master
S: 9bc2417a9cd6545ef2445eb4aa0610d586acd73b 12.114.161.16:6385slots: (0 slots) slavereplicates 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2
S: 0e34147ce2544cd90f5cce78d5493ae9e8625dfe 12.114.161.16:6384slots: (0 slots) slavereplicates f097fec937f54d147d316c1c62e26cb67c9fd059
M: f097fec937f54d147d316c1c62e26cb67c9fd059 12.114.161.16:6382slots:[6827-10922] (4096 slots) master1 additional replica(s)
M: 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2 12.114.161.16:6383slots:[12288-16383] (4096 slots) master1 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

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:6381slots:[0-6826],[10923-12287] (8192 slots) master1 additional replica(s)
S: 4ed46e0368698cd9d5af2ee84631c878b8ebc4d0 12.114.161.16:6386slots: (0 slots) slavereplicates 6e961a4765b555189708bebb69badf7dfad25cd5
M: bf73145e2eaaaa08084c9c2dad0d8c757faa48e1 12.114.161.16:6387slots: (0 slots) master                                                 # 此次显示原来Master主机的 4096个槽位已经移除,显示为 0              
S: 9bc2417a9cd6545ef2445eb4aa0610d586acd73b 12.114.161.16:6385slots: (0 slots) slavereplicates 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2
S: 0e34147ce2544cd90f5cce78d5493ae9e8625dfe 12.114.161.16:6384slots: (0 slots) slavereplicates f097fec937f54d147d316c1c62e26cb67c9fd059
M: f097fec937f54d147d316c1c62e26cb67c9fd059 12.114.161.16:6382slots:[6827-10922] (4096 slots) master1 additional replica(s)
M: 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2 12.114.161.16:6383slots:[12288-16383] (4096 slots) master1 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

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.

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

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:6381slots:[0-6826],[10923-12287] (8192 slots) master1 additional replica(s)
S: 4ed46e0368698cd9d5af2ee84631c878b8ebc4d0 12.114.161.16:6386slots: (0 slots) slavereplicates 6e961a4765b555189708bebb69badf7dfad25cd5
S: 9bc2417a9cd6545ef2445eb4aa0610d586acd73b 12.114.161.16:6385slots: (0 slots) slavereplicates 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2
S: 0e34147ce2544cd90f5cce78d5493ae9e8625dfe 12.114.161.16:6384slots: (0 slots) slavereplicates f097fec937f54d147d316c1c62e26cb67c9fd059
M: f097fec937f54d147d316c1c62e26cb67c9fd059 12.114.161.16:6382slots:[6827-10922] (4096 slots) master1 additional replica(s)
M: 78ac7be13522bd4ffd6fcf900c6c149c6938ecc2 12.114.161.16:6383slots:[12288-16383] (4096 slots) master1 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从架构”!

这篇关于【架构】Docker实现集群主从缩容【案例4/4】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/660501

相关文章

SpringBoot3实现Gzip压缩优化的技术指南

《SpringBoot3实现Gzip压缩优化的技术指南》随着Web应用的用户量和数据量增加,网络带宽和页面加载速度逐渐成为瓶颈,为了减少数据传输量,提高用户体验,我们可以使用Gzip压缩HTTP响应,... 目录1、简述2、配置2.1 添加依赖2.2 配置 Gzip 压缩3、服务端应用4、前端应用4.1 N

SpringBoot实现数据库读写分离的3种方法小结

《SpringBoot实现数据库读写分离的3种方法小结》为了提高系统的读写性能和可用性,读写分离是一种经典的数据库架构模式,在SpringBoot应用中,有多种方式可以实现数据库读写分离,本文将介绍三... 目录一、数据库读写分离概述二、方案一:基于AbstractRoutingDataSource实现动态

Python FastAPI+Celery+RabbitMQ实现分布式图片水印处理系统

《PythonFastAPI+Celery+RabbitMQ实现分布式图片水印处理系统》这篇文章主要为大家详细介绍了PythonFastAPI如何结合Celery以及RabbitMQ实现简单的分布式... 实现思路FastAPI 服务器Celery 任务队列RabbitMQ 作为消息代理定时任务处理完整

springboot循环依赖问题案例代码及解决办法

《springboot循环依赖问题案例代码及解决办法》在SpringBoot中,如果两个或多个Bean之间存在循环依赖(即BeanA依赖BeanB,而BeanB又依赖BeanA),会导致Spring的... 目录1. 什么是循环依赖?2. 循环依赖的场景案例3. 解决循环依赖的常见方法方法 1:使用 @La

Java枚举类实现Key-Value映射的多种实现方式

《Java枚举类实现Key-Value映射的多种实现方式》在Java开发中,枚举(Enum)是一种特殊的类,本文将详细介绍Java枚举类实现key-value映射的多种方式,有需要的小伙伴可以根据需要... 目录前言一、基础实现方式1.1 为枚举添加属性和构造方法二、http://www.cppcns.co

使用Python实现快速搭建本地HTTP服务器

《使用Python实现快速搭建本地HTTP服务器》:本文主要介绍如何使用Python快速搭建本地HTTP服务器,轻松实现一键HTTP文件共享,同时结合二维码技术,让访问更简单,感兴趣的小伙伴可以了... 目录1. 概述2. 快速搭建 HTTP 文件共享服务2.1 核心思路2.2 代码实现2.3 代码解读3.

MySQL双主搭建+keepalived高可用的实现

《MySQL双主搭建+keepalived高可用的实现》本文主要介绍了MySQL双主搭建+keepalived高可用的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、测试环境准备二、主从搭建1.创建复制用户2.创建复制关系3.开启复制,确认复制是否成功4.同

Java实现文件图片的预览和下载功能

《Java实现文件图片的预览和下载功能》这篇文章主要为大家详细介绍了如何使用Java实现文件图片的预览和下载功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... Java实现文件(图片)的预览和下载 @ApiOperation("访问文件") @GetMapping("

使用Sentinel自定义返回和实现区分来源方式

《使用Sentinel自定义返回和实现区分来源方式》:本文主要介绍使用Sentinel自定义返回和实现区分来源方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Sentinel自定义返回和实现区分来源1. 自定义错误返回2. 实现区分来源总结Sentinel自定

Java实现时间与字符串互相转换详解

《Java实现时间与字符串互相转换详解》这篇文章主要为大家详细介绍了Java中实现时间与字符串互相转换的相关方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、日期格式化为字符串(一)使用预定义格式(二)自定义格式二、字符串解析为日期(一)解析ISO格式字符串(二)解析自定义