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


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

    1. 新建两个node节点

    1. docker run -d \
    2. --net host \
    3. --privileged \
    4. --name redis-node-7 \
    5. --log-opt max-size=100m \
    6. --log-opt max-file=3 \
    7. -v /root/docker/redis-node-7/data:/data \
    8. redis:6.0.8 \
    9. --cluster-enabled yes \
    10. --appendonly yes \
    11. --port 16385 \
    12. --requirepass admin123
    13. docker run -d \
    14. --net host \
    15. --privileged \
    16. --name redis-node-8 \
    17. --log-opt max-size=100m \
    18. --log-opt max-file=3 \
    19. -v /root/docker/redis-node-8/data:/data \
    20. redis:6.0.8 \
    21. --cluster-enabled yes \
    22. --appendonly yes \
    23. --port 16386 \
    24. --requirepass admin123

    2. 将新的 master node 加入集群

    docker exec -it redis-node-1 bash

    redis-cli --pass admin123 --cluster add-node 你的ip:16385 你的ip:16379

    1. root@OrionEcsServer:/data# redis-cli --pass admin123 --cluster add-node 172.19.6.128:16385 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. >>> Adding node 172.19.6.128:16385 to cluster 172.19.6.128:16379
    4. >>> Performing Cluster Check (using node 172.19.6.128:16379)
    5. M: ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379
    6. slots:[0-5460] (5461 slots) master
    7. 1 additional replica(s)
    8. S: 001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383
    9. slots: (0 slots) slave
    10. replicates ff3488c654a8006784faa35b8a181a567ec2436a
    11. S: e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384
    12. slots: (0 slots) slave
    13. replicates 30dd349f6405017a5063d25b9e1d61f39db4c3dc
    14. M: 7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381
    15. slots:[10923-16383] (5461 slots) master
    16. 1 additional replica(s)
    17. M: 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380
    18. slots:[5461-10922] (5462 slots) master
    19. 1 additional replica(s)
    20. S: b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382
    21. slots: (0 slots) slave
    22. replicates 7de702973b5d649d206d4ba48c772155f6088657
    23. [OK] All nodes agree about slots configuration.
    24. >>> Check for open slots...
    25. >>> Check slots coverage...
    26. [OK] All 16384 slots covered.
    27. >>> Send CLUSTER MEET to node 172.19.6.128:16385 to make it join the cluster.
    28. [OK] New node added correctly.

    3. 检查集群状态

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

    执行后记录新master的ID 后面重新分配slot会用: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 

    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...) -> 0 keys | 5461 slots | 1 slaves.
    4. 172.19.6.128:16385 (3f081a67...) -> 0 keys | 0 slots | 0 slaves.
    5. 172.19.6.128:16381 (7de70297...) -> 0 keys | 5461 slots | 1 slaves.
    6. 172.19.6.128:16380 (30dd349f...) -> 0 keys | 5462 slots | 1 slaves.
    7. [OK] 0 keys in 4 masters.
    8. 0.00 keys per slot on average.
    9. >>> Performing Cluster Check (using node 172.19.6.128:16379)
    10. M: ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379
    11. slots:[0-5460] (5461 slots) master
    12. 1 additional replica(s)
    13. M: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 172.19.6.128:16385
    14. slots: (0 slots) master
    15. S: 001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383
    16. slots: (0 slots) slave
    17. replicates ff3488c654a8006784faa35b8a181a567ec2436a
    18. S: e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384
    19. slots: (0 slots) slave
    20. replicates 30dd349f6405017a5063d25b9e1d61f39db4c3dc
    21. M: 7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381
    22. slots:[10923-16383] (5461 slots) master
    23. 1 additional replica(s)
    24. M: 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380
    25. slots:[5461-10922] (5462 slots) master
    26. 1 additional replica(s)
    27. S: b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382
    28. slots: (0 slots) slave
    29. replicates 7de702973b5d649d206d4ba48c772155f6088657
    30. [OK] All nodes agree about slots configuration.
    31. >>> Check for open slots...
    32. >>> Check slots coverage...
    33. [OK] All 16384 slots covered.

    4. 重新分配 slot


    redis-cli --pass admin123 --cluster reshard 你的:16379

    第一次输入: 新分配的槽数 4096 (16384/4=4096)

    第二次输入: 槽的接收者ID 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 上面记录ID的 (这里不要有空格)

    第三次输入: 槽分配的数量 all 从所有节点均匀分配

    第四次输入: 确认操作 yes 

    执行完成后耐心等待槽的重新分配

    1. root@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:[0-5460] (5461 slots) master
    6. 1 additional replica(s)
    7. M: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 172.19.6.128:16385
    8. slots: (0 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:[10923-16383] (5461 slots) master
    17. 1 additional replica(s)
    18. M: 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380
    19. slots:[5461-10922] (5462 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? 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
    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: all
    34. Ready to move 4096 slots.
    35. Source nodes:
    36. M: ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379
    37. slots:[0-5460] (5461 slots) master
    38. 1 additional replica(s)
    39. M: 7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381
    40. slots:[10923-16383] (5461 slots) master
    41. 1 additional replica(s)
    42. M: 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380
    43. slots:[5461-10922] (5462 slots) master
    44. 1 additional replica(s)
    45. Destination node:
    46. M: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 172.19.6.128:16385
    47. slots: (0 slots) master
    48. Resharding plan:
    49. Moving slot 5461 from 30dd349f6405017a5063d25b9e1d61f39db4c3dc
    50. ...
    51. Moving slot 12287 from 7de702973b5d649d206d4ba48c772155f6088657
    52. Do you want to proceed with the proposed reshard plan (yes/no)? yes
    53. Moving slot 5461 from 172.19.6.128:16380 to 172.19.6.128:16385:
    54. .....
    55. Moving slot 5693 from 172.19.6.128:16380 to 172.19.6.128:16385:
    56. root@OrionEcsServer:/data#

    5. 重新检查机器状态

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

    这里可以发现 16385 已经重新分配了4096个slot

    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...) -> 0 keys | 4096 slots | 1 slaves.
    4. 172.19.6.128:16385 (3f081a67...) -> 0 keys | 4096 slots | 0 slaves.
    5. 172.19.6.128:16381 (7de70297...) -> 0 keys | 4096 slots | 1 slaves.
    6. 172.19.6.128:16380 (30dd349f...) -> 0 keys | 4096 slots | 1 slaves.
    7. [OK] 0 keys in 4 masters.
    8. 0.00 keys per slot on average.
    9. >>> Performing Cluster Check (using node 172.19.6.128:16379)
    10. M: ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379
    11. slots:[1365-5460] (4096 slots) master
    12. 1 additional replica(s)
    13. M: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 172.19.6.128:16385
    14. slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
    15. S: 001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383
    16. slots: (0 slots) slave
    17. replicates ff3488c654a8006784faa35b8a181a567ec2436a
    18. S: e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384
    19. slots: (0 slots) slave
    20. replicates 30dd349f6405017a5063d25b9e1d61f39db4c3dc
    21. M: 7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381
    22. slots:[12288-16383] (4096 slots) master
    23. 1 additional replica(s)
    24. M: 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380
    25. slots:[6827-10922] (4096 slots) master
    26. 1 additional replica(s)
    27. S: b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382
    28. slots: (0 slots) slave
    29. replicates 7de702973b5d649d206d4ba48c772155f6088657
    30. [OK] All nodes agree about slots configuration.
    31. >>> Check for open slots...
    32. >>> Check slots coverage...
    33. [OK] All 16384 slots covered.

    6. 给新的 master node 分配 slave
    redis-cli --pass admin123 --cluster add-node 你的ip:16386 你的ip:16385 --cluster-slave --cluster-master-id 刚刚记录的masterId

    1. root@OrionEcsServer:/data# redis-cli --pass admin123 --cluster --cluster add-node 172.19.6.128:16386 172.19.6.128:16385 --cluster-slave --cluster-master-id 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6
    2. Using a password with '-a' or '-u' option on the command line interface may not be safe..6.128:16385 --cluster-slave --cluster-master-id 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6>>> Adding node 172.19.6.128:16386 to cluster 172.19.6.128:16385
    3. >>> Performing Cluster Check (using node 172.19.6.128:16385)
    4. M: 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 172.19.6.128:16385
    5. slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
    6. S: 001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383
    7. slots: (0 slots) slave
    8. replicates ff3488c654a8006784faa35b8a181a567ec2436a
    9. S: e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384
    10. slots: (0 slots) slave
    11. replicates 30dd349f6405017a5063d25b9e1d61f39db4c3dc
    12. M: ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379
    13. slots:[1365-5460] (4096 slots) master
    14. 1 additional replica(s)
    15. S: b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382
    16. slots: (0 slots) slave
    17. replicates 7de702973b5d649d206d4ba48c772155f6088657
    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. [OK] All nodes agree about slots configuration.
    25. >>> Check for open slots...
    26. >>> Check slots coverage...
    27. [OK] All 16384 slots covered.
    28. >>> Send CLUSTER MEET to node 172.19.6.128:16386 to make it join the cluster.
    29. Waiting for the cluster to join
    30. >>> Configure node as replica of 172.19.6.128:16385.
    31. [OK] New node added correctly.

    7. 查看集群状态

    redis-cli -p 16379 -c --pass admin123
    cluster info
    cluster nodes  

    这里可以发现 16386 已经挂载到 16395 下面了, 变成了4主4从

    1. root@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:8
    10. cluster_size:4
    11. cluster_current_epoch:7
    12. cluster_my_epoch:1
    13. cluster_stats_messages_ping_sent:2016
    14. cluster_stats_messages_pong_sent:2026
    15. cluster_stats_messages_update_sent:3
    16. cluster_stats_messages_sent:4045
    17. cluster_stats_messages_ping_received:2020
    18. cluster_stats_messages_pong_received:2016
    19. cluster_stats_messages_meet_received:6
    20. cluster_stats_messages_received:4042
    21. 127.0.0.1:16379> cluster nodes
    22. ff3488c654a8006784faa35b8a181a567ec2436a 172.19.6.128:16379@26379 myself,master - 0 1670161348000 1 connected 1365-5460
    23. a2bd918b2e2072ab238bc1937710ea7ed05a7c03 172.19.6.128:16386@26386 slave 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 0 1670161350000 7 connected
    24. 3f081a67bbc0a1e7f9a0a0a27704cc5ee513fee6 172.19.6.128:16385@26385 master - 0 1670161350310 7 connected 0-1364 5461-6826 10923-12287
    25. 001837d619d76cda8e0e537321032363970f5bc9 172.19.6.128:16383@26383 slave ff3488c654a8006784faa35b8a181a567ec2436a 0 1670161345000 1 connected
    26. e02423adc0d998e84a7152e099a96402ea01c3e8 172.19.6.128:16384@26384 slave 30dd349f6405017a5063d25b9e1d61f39db4c3dc 0 1670161349000 2 connected
    27. 7de702973b5d649d206d4ba48c772155f6088657 172.19.6.128:16381@26381 master - 0 1670161351000 3 connected 12288-16383
    28. 30dd349f6405017a5063d25b9e1d61f39db4c3dc 172.19.6.128:16380@26380 master - 0 1670161349309 2 connected 6827-10922
    29. b76af89d5b835c36201479c9284f2a4ad4b8f820 172.19.6.128:16382@26382 slave 7de702973b5d649d206d4ba48c772155f6088657 0 1670161351312 3 connected
    30. 127.0.0.1:16379>

    8. 测试

    set a 1

    set b 2

    set c 3

  • 相关阅读:
    react中设置activeClassName的笔记
    数据库表设计优化
    深度之眼(二十三)——Python:Sklearn库
    Vue 3 中用组合式函数和 Shared Worker 实现后台分片上传(带哈希计算)
    【项目调优】项目从EhCache缓存变为redis之后,加载菜单变得极其缓慢
    腾讯云数据安全中台保护方案获“首届全国商用密码应用优秀案例”
    ioDraw - 超好用的在线白板,能够手绘各种流程图、架构图
    【路径规划-VRP问题】基于混合K-Means和蚁群算法求解带容量车辆路径规划CVRP问题附matlab代码
    Spring Boot配置Tomcat容器、Jetty容器、Undertow容器
    MYSQL数据库(64位)详细安装
  • 原文地址:https://blog.csdn.net/qq_41011894/article/details/128177386