集群涉及到的源文件:

config/node*/redis.conf

执行命令

  1. docker-compose -f docker-compose.yml up -d
  2. sh start.sh

docker-compose.yml详细代码

  1. version: '3.4'
  2. services:
  3. node1:
  4. image: redis:5.0.5
  5. container_name: redis-node1
  6. restart: always
  7. network_mode: "host"
  8. # ports:
  9. # - 6061:6061
  10. # - 16061:16061
  11. volumes:
  12. - ./data/node1:/data
  13. - ./config/node1:/usr/local/etc/redis
  14. command:
  15. redis-server /usr/local/etc/redis/redis.conf
  16. node2:
  17. image: redis:5.0.5
  18. container_name: redis-node2
  19. restart: always
  20. network_mode: "host"
  21. # ports:
  22. # - 6062:6062
  23. # - 16062:16062
  24. volumes:
  25. - ./data/node2:/data
  26. - ./config/node2:/usr/local/etc/redis
  27. command:
  28. redis-server /usr/local/etc/redis/redis.conf
  29. node3:
  30. image: redis:5.0.5
  31. container_name: redis-node3
  32. restart: always
  33. network_mode: "host"
  34. # ports:
  35. # - 6063:6063
  36. # - 16063:16063
  37. volumes:
  38. - ./data/node3:/data
  39. - ./config/node3:/usr/local/etc/redis
  40. command:
  41. redis-server /usr/local/etc/redis/redis.conf
  42. node4:
  43. image: redis:5.0.5
  44. container_name: redis-node4
  45. restart: always
  46. network_mode: "host"
  47. # ports:
  48. # - 6064:6064
  49. # - 16064:16064
  50. volumes:
  51. - ./data/node4:/data
  52. - ./config/node4:/usr/local/etc/redis
  53. command:
  54. redis-server /usr/local/etc/redis/redis.conf
  55. node5:
  56. image: redis:5.0.5
  57. container_name: redis-node5
  58. restart: always
  59. network_mode: "host"
  60. # ports:
  61. # - 6065:6065
  62. # - 16065:16065
  63. volumes:
  64. - ./data/node5:/data
  65. - ./config/node5:/usr/local/etc/redis
  66. command:
  67. redis-server /usr/local/etc/redis/redis.conf
  68. node6:
  69. image: redis:5.0.5
  70. container_name: redis-node6
  71. restart: always
  72. network_mode: "host"
  73. # ports:
  74. # - 6066:6066
  75. # - 16066:16066
  76. volumes:
  77. - ./data/node6:/data
  78. - ./config/node6:/usr/local/etc/redis
  79. command:
  80. redis-server /usr/local/etc/redis/redis.conf

start.sh详细代码

  1. #!/bin/bash
  2. docker-compose up -d
  3. sleep 20
  4. docker run --rm -it zvelo/redis-trib create --replicas 1 172.31.161.97:6061 172.31.161.97:6062 172.31.161.97:6063 172.31.161.97:6064 172.31.161.97:6065 172.31.161.97:6066