• docker 安装 redis 6.0.8 cluster 实战 (3主3从) 安装篇


    1. 创建并启动6个node节点

    1. docker run -d \
    2. --net host \
    3. --privileged \
    4. --name redis-node-1 \
    5. --log-opt max-size=100m \
    6. --log-opt max-file=3 \
    7. -v /root/docker/redis-node-1/data:/data \
    8. redis:6.0.8 \
    9. --cluster-enabled yes \
    10. --appendonly yes \
    11. --port 16379 \
    12. --requirepass admin123
    13. docker run -d \
    14. --net host \
    15. --privileged \
    16. --name redis-node-2 \
    17. --log-opt max-size=100m \
    18. --log-opt max-file=3 \
    19. -v /root/docker/redis-node-2/data:/data \
    20. redis:6.0.8 \
    21. --cluster-enabled yes \
    22. --appendonly yes \
    23. --port 16380 \
    24. --requirepass admin123
    25. docker run -d \
    26. --net host \
    27. --privileged \
    28. --name redis-node-3 \
    29. --log-opt max-size=100m \
    30. --log-opt max-file=3 \
    31. -v /root/docker/redis-node-3/data:/data \
    32. redis:6.0.8 \
    33. --cluster-enabled yes \
    34. --appendonly yes \
    35. --port 16381 \
    36. --requirepass admin123
    37. docker run -d \
    38. --net host \
    39. --privileged \
    40. --name redis-node-4 \
    41. --log-opt max-size=100m \
    42. --log-opt max-file=3 \
    43. -v /root/docker/redis-node-4/data:/data \
    44. redis:6.0.8 \
    45. --cluster-enabled yes \
    46. --appendonly yes \
    47. --port 16382 \
    48. --requirepass admin123
    49. docker run -d \
    50. --net host \
    51. --privileged \
    52. --name redis-node-5 \
    53. --log-opt max-size=100m \
    54. --log-opt max-file=3 \
    55. -v /root/docker/redis-node-5/data:/data \
    56. redis:6.0.8 \
    57. --cluster-enabled yes \
    58. --appendonly yes \
    59. --port 16383 \
    60. --requirepass admin123
    61. docker run -d \
    62. --net host \
    63. --privileged \
    64. --name redis-node-6 \
    65. --log-opt max-size=100m \
    66. --log-opt max-file=3 \
    67. -v /root/docker/redis-node-6/data:/data \
    68. redis:6.0.8 \
    69. --cluster-enabled yes \
    70. --appendonly yes \
    71. --port 16384 \
    72. --requirepass admin123

    这里使用主机网络模式, 就不需要做端口映射了, 可以参考上篇博客的配置 传送 

    2. 创建redis集群 

        # 进入节点容器
        docker exec -it redis-node-1 bash
        # 创建命令
        redis-cli --pass admin123 --cluster create 你的ip:16379 你的ip:16380 你的ip:16381 你的ip:16382 你的ip:16383 你的ip:16384 --cluster-replicas 1

        --pass 指定密码

        --cluster-replicas 指定副本数量, 也就是几个从节点 

        执行完命令后输入yes 等待集群的创建

    1. [root@OrionEcsServer ~]# docker exec -it redis-node-1 bash
    2. root@OrionEcsServer:/data# redis-cli --pass admin123 --cluster create 172.19.6.128:16379 172.19.6.128:16380 172.19.6.128:16381 172.19.6.128:16382 172.19.6.128:16383 172.19.6.128:16384 --cluster-replicas 1
    3. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    4. >>> Performing hash slots allocation on 6 nodes...
    5. Master[0] -> Slots 0 - 5460
    6. Master[1] -> Slots 5461 - 10922
    7. Master[2] -> Slots 10923 - 16383
    8. Adding replica 172.19.6.128:16383 to 172.19.6.128:16379
    9. Adding replica 172.19.6.128:16384 to 172.19.6.128:16380
    10. Adding replica 172.19.6.128:16382 to 172.19.6.128:16381
    11. >>> Trying to optimize slaves allocation for anti-affinity
    12. [WARNING] Some slaves are in the same host as their master
    13. M: 5ddfdb998c64916b2b624fa1d70acab33cf39fc3 172.19.6.128:16379
    14. slots:[0-5460] (5461 slots) master
    15. M: 344331df652c7db5599af38507739aca49cab16c 172.19.6.128:16380
    16. slots:[5461-10922] (5462 slots) master
    17. M: b04e2493efedc56dec34bc796e9a4f4817b98845 172.19.6.128:16381
    18. slots:[10923-16383] (5461 slots) master
    19. S: 25a5b5357d6861328b8734f3db5a1db40b419ab1 172.19.6.128:16382
    20. replicates 344331df652c7db5599af38507739aca49cab16c
    21. S: 47fac839bbb32e00ee592d3ecf095426ae66f27d 172.19.6.128:16383
    22. replicates b04e2493efedc56dec34bc796e9a4f4817b98845
    23. S: 6626185f45bdb336597b0924959f066f8bc5283f 172.19.6.128:16384
    24. replicates 5ddfdb998c64916b2b624fa1d70acab33cf39fc3
    25. Can I set the above configuration? (type 'yes' to accept): yes
    26. >>> Nodes configuration updated
    27. >>> Assign a different config epoch to each node
    28. >>> Sending CLUSTER MEET messages to join the cluster
    29. Waiting for the cluster to join
    30. .
    31. >>> Performing Cluster Check (using node 172.19.6.128:16379)
    32. M: 5ddfdb998c64916b2b624fa1d70acab33cf39fc3 172.19.6.128:16379
    33. slots:[0-5460] (5461 slots) master
    34. 1 additional replica(s)
    35. M: 344331df652c7db5599af38507739aca49cab16c 172.19.6.128:16380
    36. slots:[5461-10922] (5462 slots) master
    37. 1 additional replica(s)
    38. S: 25a5b5357d6861328b8734f3db5a1db40b419ab1 172.19.6.128:16382
    39. slots: (0 slots) slave
    40. replicates 344331df652c7db5599af38507739aca49cab16c
    41. M: b04e2493efedc56dec34bc796e9a4f4817b98845 172.19.6.128:16381
    42. slots:[10923-16383] (5461 slots) master
    43. 1 additional replica(s)
    44. S: 47fac839bbb32e00ee592d3ecf095426ae66f27d 172.19.6.128:16383
    45. slots: (0 slots) slave
    46. replicates b04e2493efedc56dec34bc796e9a4f4817b98845
    47. S: 6626185f45bdb336597b0924959f066f8bc5283f 172.19.6.128:16384
    48. slots: (0 slots) slave
    49. replicates 5ddfdb998c64916b2b624fa1d70acab33cf39fc3
    50. [OK] All nodes agree about slots configuration.
    51. >>> Check for open slots...
    52. >>> Check slots coverage...
    53. [OK] All 16384 slots covered.

    3. 检查集群状态
            # 连接  
            redis-cli -p 16379 -c --pass admin123
            # 查看集群信息
            cluster info
            # 查看集群节点
            cluster nodes

            这里大概这样就代表集群创建成功了

    1. 127.0.0.1:16379> cluster nodes
    2. 344331df652c7db5599af38507739aca49cab16c 172.19.6.128:16380@26380 master - 0 1670158269000 2 connected 5461-10922
    3. 25a5b5357d6861328b8734f3db5a1db40b419ab1 172.19.6.128:16382@26382 slave 344331df652c7db5599af38507739aca49cab16c 0 1670158266000 2 connected
    4. 5ddfdb998c64916b2b624fa1d70acab33cf39fc3 172.19.6.128:16379@26379 myself,master - 0 1670158268000 1 connected 0-5460
    5. b04e2493efedc56dec34bc796e9a4f4817b98845 172.19.6.128:16381@26381 master - 0 1670158268000 3 connected 10923-16383
    6. 47fac839bbb32e00ee592d3ecf095426ae66f27d 172.19.6.128:16383@26383 slave b04e2493efedc56dec34bc796e9a4f4817b98845 0 1670158268599 3 connected
    7. 6626185f45bdb336597b0924959f066f8bc5283f 172.19.6.128:16384@26384 slave 5ddfdb998c64916b2b624fa1d70acab33cf39fc3 0 1670158269601 1 connected

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

  • 相关阅读:
    PTL电子标签助力仓储行业转型升级提升拣货效率降低误差率
    java spring cloud 企业电子招标采购系统源码:营造全面规范安全的电子招投标环境,促进招投标市场健康可持续发展
    阿里云OSS存储的应用
    11月16日,每日信息差
    【2023 · CANN训练营第一季】基于昇腾910的TF网络脚本训练(ModelArts平台)
    Springboot利用Security做OAuth2授权验证
    MASA Auth - 从用户的角度看整体设计
    20230921研发面经总结
    浅尝Spring注解开发_AOP原理及完整过程分析(源码)
    【2023研电赛】安谋科技企业命题二等奖:基于R329的AI交互早教机器人
  • 原文地址:https://blog.csdn.net/qq_41011894/article/details/128177053