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

相关内容

热门资讯

保存时出现了1个错误,导致这篇... 当保存文章时出现错误时,可以通过以下步骤解决问题:查看错误信息:查看错误提示信息可以帮助我们了解具体...
汇川伺服电机位置控制模式参数配... 1. 基本控制参数设置 1)设置位置控制模式   2)绝对值位置线性模...
不能访问光猫的的管理页面 光猫是现代家庭宽带网络的重要组成部分,它可以提供高速稳定的网络连接。但是,有时候我们会遇到不能访问光...
不一致的条件格式 要解决不一致的条件格式问题,可以按照以下步骤进行:确定条件格式的规则:首先,需要明确条件格式的规则是...
本地主机上的图像未显示 问题描述:在本地主机上显示图像时,图像未能正常显示。解决方法:以下是一些可能的解决方法,具体取决于问...
表格列调整大小出现问题 问题描述:表格列调整大小出现问题,无法正常调整列宽。解决方法:检查表格的布局方式是否正确。确保表格使...
表格中数据未显示 当表格中的数据未显示时,可能是由于以下几个原因导致的:HTML代码问题:检查表格的HTML代码是否正...
Android|无法访问或保存... 这个问题可能是由于权限设置不正确导致的。您需要在应用程序清单文件中添加以下代码来请求适当的权限:此外...
【NI Multisim 14...   目录 序言 一、工具栏 🍊1.“标准”工具栏 🍊 2.视图工具...
银河麒麟V10SP1高级服务器... 银河麒麟高级服务器操作系统简介: 银河麒麟高级服务器操作系统V10是针对企业级关键业务...