docker 安装 redis 6.0.8 cluster 实战 (3主3从) 动态缩容
创始人
2024-03-18 03:08:27
0

这里将上篇博客扩容的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:16379slots:[1365-5460] (4096 slots) master1 additional replica(s)
S: a2bd918b2e2072ab238bc1937710ea7ed05a7c03 172.19.6.128:16386slots: (0 slots) slavereplicates 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
M: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 172.19.6.128:16385slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master1 additional replica(s)
S: 001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383slots: (0 slots) slavereplicates ff3488c654a8006784faa35b8a181a567ec2436a
S: e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384slots: (0 slots) slavereplicates 30dd349f6405017a5063d25b9e1d61f39db4c3dc
M: 7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381slots:[12288-16383] (4096 slots) master1 additional replica(s)
M: 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380slots:[6827-10922] (4096 slots) master1 additional replica(s)
S: b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382slots: (0 slots) slavereplicates 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:16379slots:[1365-5460] (4096 slots) master1 additional replica(s)
M: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 172.19.6.128:16385slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: 001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383slots: (0 slots) slavereplicates ff3488c654a8006784faa35b8a181a567ec2436a
S: e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384slots: (0 slots) slavereplicates 30dd349f6405017a5063d25b9e1d61f39db4c3dc
M: 7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381slots:[12288-16383] (4096 slots) master1 additional replica(s)
M: 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380slots:[6827-10922] (4096 slots) master1 additional replica(s)
S: b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382slots: (0 slots) slavereplicates 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: doneReady to move 4096 slots.Source nodes:M: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 172.19.6.128:16385slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) masterDestination node:M: ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379slots:[1365-5460] (4096 slots) master1 additional replica(s)Resharding plan:Moving slot 0 from 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6Moving slot 1 from 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6Moving slot 2 from 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6...Moving slot 12286 from 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6Moving 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:16379slots:[0-6826],[10923-12287] (8192 slots) master1 additional replica(s)
S: 001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383slots: (0 slots) slavereplicates ff3488c654a8006784faa35b8a181a567ec2436a
S: e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384slots: (0 slots) slavereplicates 30dd349f6405017a5063d25b9e1d61f39db4c3dc
M: 7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381slots:[12288-16383] (4096 slots) master1 additional replica(s)
M: 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380slots:[6827-10922] (4096 slots) master1 additional replica(s)
S: b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382slots: (0 slots) slavereplicates 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

相关内容

热门资讯

AWSECS:访问外部网络时出... 如果您在AWS ECS中部署了应用程序,并且该应用程序需要访问外部网络,但是无法正常访问,可能是因为...
AWSElasticBeans... 在Dockerfile中手动配置nginx反向代理。例如,在Dockerfile中添加以下代码:FR...
银河麒麟V10SP1高级服务器... 银河麒麟高级服务器操作系统简介: 银河麒麟高级服务器操作系统V10是针对企业级关键业务...
北信源内网安全管理卸载 北信源内网安全管理是一款网络安全管理软件,主要用于保护内网安全。在日常使用过程中,卸载该软件是一种常...
AWR报告解读 WORKLOAD REPOSITORY PDB report (PDB snapshots) AW...
AWS管理控制台菜单和权限 要在AWS管理控制台中创建菜单和权限,您可以使用AWS Identity and Access Ma...
​ToDesk 远程工具安装及... 目录 前言 ToDesk 优势 ToDesk 下载安装 ToDesk 功能展示 文件传输 设备链接 ...
群晖外网访问终极解决方法:IP... 写在前面的话 受够了群晖的quickconnet的小水管了,急需一个新的解决方法&#x...
不能访问光猫的的管理页面 光猫是现代家庭宽带网络的重要组成部分,它可以提供高速稳定的网络连接。但是,有时候我们会遇到不能访问光...
Azure构建流程(Power... 这可能是由于配置错误导致的问题。请检查构建流程任务中的“发布构建制品”步骤,确保正确配置了“Arti...