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

相关内容

热门资讯

前端-session、jwt 目录:   (1)session (2&#x...
linux入门---制作进度条 了解缓冲区 我们首先来看看下面的操作: 我们首先创建了一个文件并在这个文件里面添加了...
关于测试,我发现了哪些新大陆 关于测试 平常也只是听说过一些关于测试的术语,但并没有使用过测试工具。偶然看到编程老师...
前缀和与对数器与二分法 1. 前缀和 假设有一个数组,我们想大量频繁的去访问L到R这个区间的和,...
nodejs:本地安装nvm实... 一、背景-使用不同版本node的原因 vue3+ts、nuxt3版本,node...
JAVA集合知识整理 Java集合知识整理 HashMap相关 HashMap的底层数据结构:jdk1.8之...
无刷直流电机介绍及单片机控制实... 无刷直流电机介绍及单片机控制实例前言基本概念优势与劣势使用寿命基本结构使用单片机控制实例电子调速器&...
fwdiary(2) dp2 1.传纸条  AcWing 275. 传纸条 - AcWing 走两条路,走一条最大的...
常用的DOS命令 常用的DOS命令 DOS(Disk Operating System,磁...
<C++> 类和对象(下) 1.const成员函数将const修饰的“成员函数”称之为const成员函数,cons...