• docker 安装 redis 6.0.8 cluster 实战 (3主3从) 动态缩容


    这里将上篇博客扩容的4主4从 缩容为3主3从

    1. 检查集群状态
    redis-cli --pass admin123 --cluster check 你的ip:16379
    并且记录 16385, 16386 的ID

    1. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    2. 172.19.6.128:16379 (ff3488c6...) -> 1 keys | 4096 slots | 1 slaves.
    3. 172.19.6.128:16385 (3f081a67...) -> 1 keys | 4096 slots | 1 slaves.
    4. 172.19.6.128:16381 (7de70297...) -> 1 keys | 4096 slots | 1 slaves.
    5. 172.19.6.128:16380 (30dd349f...) -> 1 keys | 4096 slots | 1 slaves.
    6. [OK] 4 keys in 4 masters.
    7. 0.00 keys per slot on average.
    8. >>> Performing Cluster Check (using node 172.19.6.128:16379)
    9. M: ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379
    10. slots:[1365-5460] (4096 slots) master
    11. 1 additional replica(s)
    12. S: a2bd918b2e2072ab238bc1937710ea7ed05a7c03 172.19.6.128:16386
    13. slots: (0 slots) slave
    14. replicates 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
    15. M: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 172.19.6.128:16385
    16. slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
    17. 1 additional replica(s)
    18. S: 001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383
    19. slots: (0 slots) slave
    20. replicates ff3488c654a8006784faa35b8a181a567ec2436a
    21. S: e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384
    22. slots: (0 slots) slave
    23. replicates 30dd349f6405017a5063d25b9e1d61f39db4c3dc
    24. M: 7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381
    25. slots:[12288-16383] (4096 slots) master
    26. 1 additional replica(s)
    27. M: 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380
    28. slots:[6827-10922] (4096 slots) master
    29. 1 additional replica(s)
    30. S: b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382
    31. slots: (0 slots) slave
    32. replicates 7de702973b5d649d206d4ba48c772155f6088657
    33. [OK] All nodes agree about slots configuration.
    34. >>> Check for open slots...
    35. >>> Check slots coverage...
    36. [OK] All 16384 slots covered.
    37. root@OrionEcsServer:/data#

    2. 清除 slave 节点
    redis-cli --pass admin123 --cluster del-node 你的ip:16386 刚刚记录的slaveId

    1. root@OrionEcsServer:/data# redis-cli --pass admin123 --cluster del-node 172.19.6.128:16386 a2bd918b2e2072ab238bc1937710ea7ed05a7c03
    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    3. >>> Removing node a2bd918b2e2072ab238bc1937710ea7ed05a7c03 from cluster 172.19.6.128:16386
    4. >>> Sending CLUSTER FORGET messages to the cluster...
    5. >>> Sending CLUSTER RESET SOFT to the deleted node.
    6. root@OrionEcsServer:/data#

    3. 重新分配 slot
    redis-cli --pass admin123 --cluster reshard 你的ip:16379
    第一次输入: 需要移动的槽数 4096
    第二次输入: 接收的 nodeId (16379) ff3488c654a8006784faa35b8a181a567ec2436a
    第三次输入: 移动的 nodeId (16385) 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
    第四次输入: 结束 done
    第五次输入: yes 

    这里我图方便, 将4096个槽全部分配给了16379, 其实这里可以多次执行重新分配的操作

    1. t@OrionEcsServer:/data# redis-cli --pass admin123 --cluster reshard 172.19.6.128:16379
    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    3. >>> Performing Cluster Check (using node 172.19.6.128:16379)
    4. M: ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379
    5. slots:[1365-5460] (4096 slots) master
    6. 1 additional replica(s)
    7. M: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 172.19.6.128:16385
    8. slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
    9. S: 001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383
    10. slots: (0 slots) slave
    11. replicates ff3488c654a8006784faa35b8a181a567ec2436a
    12. S: e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384
    13. slots: (0 slots) slave
    14. replicates 30dd349f6405017a5063d25b9e1d61f39db4c3dc
    15. M: 7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381
    16. slots:[12288-16383] (4096 slots) master
    17. 1 additional replica(s)
    18. M: 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380
    19. slots:[6827-10922] (4096 slots) master
    20. 1 additional replica(s)
    21. S: b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382
    22. slots: (0 slots) slave
    23. replicates 7de702973b5d649d206d4ba48c772155f6088657
    24. [OK] All nodes agree about slots configuration.
    25. >>> Check for open slots...
    26. >>> Check slots coverage...
    27. [OK] All 16384 slots covered.
    28. How many slots do you want to move (from 1 to 16384)? 4096
    29. What is the receiving node ID? ff3488c654a8006784faa35b8a181a567ec2436a
    30. Please enter all the source node IDs.
    31. Type 'all' to use all the nodes as source nodes for the hash slots.
    32. Type 'done' once you entered all the source nodes IDs.
    33. Source node #1: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
    34. Source node #2: done
    35. Ready to move 4096 slots.
    36. Source nodes:
    37. M: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 172.19.6.128:16385
    38. slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
    39. Destination node:
    40. M: ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379
    41. slots:[1365-5460] (4096 slots) master
    42. 1 additional replica(s)
    43. Resharding plan:
    44. Moving slot 0 from 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
    45. Moving slot 1 from 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
    46. Moving slot 2 from 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
    47. ...
    48. Moving slot 12286 from 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
    49. Moving slot 12287 from 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
    50. Do you want to proceed with the proposed reshard plan (yes/no)? yes
    51. Moving slot 0 from 172.19.6.128:16385 to 172.19.6.128:16379:
    52. Moving slot 1 from 172.19.6.128:16385 to 172.19.6.128:16379:
    53. Moving slot 2 from 172.19.6.128:16385 to 172.19.6.128:16379:
    54. ...
    55. Moving slot 12287 from 172.19.6.128:16385 to 172.19.6.128:16379:
    56. root@OrionEcsServer:/data#

    4. 清除 master 节点
    redis-cli --pass admin123 --cluster del-node 你的ip16385 刚刚记录的masterId

    1. root@OrionEcsServer:/data# redis-cli --pass admin123 --cluster del-node 172.19.6.128:16385 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    3. >>> Removing node 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 from cluster 172.19.6.128:16385
    4. >>> Sending CLUSTER FORGET messages to the cluster...
    5. >>> Sending CLUSTER RESET SOFT to the deleted node.
    6. root@OrionEcsServer:/data#

    5. 检查集群状态

    redis-cli --pass admin123 --cluster check 你的ip:16379

    这里可以发现已经变成了3主3从

    1. root@OrionEcsServer:/data# redis-cli --pass admin123 --cluster check 172.19.6.128:16379
    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    3. 172.19.6.128:16379 (ff3488c6...) -> 2 keys | 8192 slots | 1 slaves.
    4. 172.19.6.128:16381 (7de70297...) -> 1 keys | 4096 slots | 1 slaves.
    5. 172.19.6.128:16380 (30dd349f...) -> 1 keys | 4096 slots | 1 slaves.
    6. [OK] 4 keys in 3 masters.
    7. 0.00 keys per slot on average.
    8. >>> Performing Cluster Check (using node 172.19.6.128:16379)
    9. M: ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379
    10. slots:[0-6826],[10923-12287] (8192 slots) master
    11. 1 additional replica(s)
    12. S: 001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383
    13. slots: (0 slots) slave
    14. replicates ff3488c654a8006784faa35b8a181a567ec2436a
    15. S: e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384
    16. slots: (0 slots) slave
    17. replicates 30dd349f6405017a5063d25b9e1d61f39db4c3dc
    18. M: 7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381
    19. slots:[12288-16383] (4096 slots) master
    20. 1 additional replica(s)
    21. M: 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380
    22. slots:[6827-10922] (4096 slots) master
    23. 1 additional replica(s)
    24. S: b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382
    25. slots: (0 slots) slave
    26. replicates 7de702973b5d649d206d4ba48c772155f6088657
    27. [OK] All nodes agree about slots configuration.
    28. >>> Check for open slots...
    29. >>> Check slots coverage...
    30. [OK] All 16384 slots covered.
    31. root@OrionEcsServer:/data#

    6. 查看集群状态
    redis-cli -p 16379 -c --pass admin123
    cluster info
    cluster nodes  

    1. oot@OrionEcsServer:/data# redis-cli -p 16379 -c --pass admin123
    2. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    3. 127.0.0.1:16379> cluster info
    4. cluster_state:ok
    5. cluster_slots_assigned:16384
    6. cluster_slots_ok:16384
    7. cluster_slots_pfail:0
    8. cluster_slots_fail:0
    9. cluster_known_nodes:6
    10. cluster_size:3
    11. cluster_current_epoch:8
    12. cluster_my_epoch:8
    13. cluster_stats_messages_ping_sent:3921
    14. cluster_stats_messages_pong_sent:3915
    15. cluster_stats_messages_update_sent:4
    16. cluster_stats_messages_sent:7840
    17. cluster_stats_messages_ping_received:3909
    18. cluster_stats_messages_pong_received:3921
    19. cluster_stats_messages_meet_received:6
    20. cluster_stats_messages_received:7836
    21. 127.0.0.1:16379> cluster nodes
    22. ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379@26379 myself,master - 0 1670163237000 8 connected 0-6826 10923-12287
    23. 001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383@26383 slave ff3488c654a8006784faa35b8a181a567ec2436a 0 1670163236781 8 connected
    24. e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384@26384 slave 30dd349f6405017a5063d25b9e1d61f39db4c3dc 0 1670163237784 2 connected
    25. 7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381@26381 master - 0 1670163235000 3 connected 12288-16383
    26. 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380@26380 master - 0 1670163234778 2 connected 6827-10922
    27. b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382@26382 slave 7de702973b5d649d206d4ba48c772155f6088657 0 1670163235781 3 connected
    28. 127.0.0.1:16379>

    7. 测试
            set a 1
            set b 2
            set c 3

  • 相关阅读:
    Linux 软件包下载加速工具:APT Proxy
    Tomcat服务部署
    LeetCode每日一题——828. 统计子串中的唯一字符
    python(牛客)试题解析3 - 困难
    FPGA图像处理学习——人脸检测
    Linux线程调度策略与优先级
    js控制手机蓝牙
    RK3568的CAN驱动适配
    Ambari安装部署—基础软件环境说明
    day04-前台首页、导出项目依赖
  • 原文地址:https://blog.csdn.net/qq_41011894/article/details/128178225