docker-compose.yml
version: '3' services: master1: image: redis:4.0.14-alpine container_name: redis-cluster1-master command: redis-server /etc/redis/redis.conf stdin_open: true tty: true volumes: - /path/to/redis-cluster/cluster1/master/redis.conf:/etc/redis/redis.conf - /path/to/redis-cluster/cluster1/master/data:/data ports: - 6379:6379 networks: redisNet: ipv4_address: ip1 follow1: image: redis:4.0.14-alpine container_name: redis-cluster1-follower command: redis-server /etc/redis/redis.conf stdin_open: true tty: true volumes: - /path/to/redis-cluster/cluster1/follower/redis.conf:/etc/redis/redis.conf - /path/to/redis-cluster/cluster1/follower/data:/data ports: - 6380:6379 networks: redisNet: ipv4_address: ip2 master2: image: redis:4.0.14-alpine container_name: redis-cluster2-master command: redis-server /etc/redis/redis.conf stdin_open: true tty: true volumes: - /path/to/redis-cluster/cluster2/master/redis.conf:/etc/redis/redis.conf - /path/to/redis-cluster/cluster2/master/data:/data ports: - 6381:6379 networks: redisNet: ipv4_address: ip3 follow2: image: redis:4.0.14-alpine container_name: redis-cluster2-follower command: redis-server /etc/redis/redis.conf stdin_open: true tty: true volumes: - /path/to/redis-cluster/cluster2/follower/redis.conf:/etc/redis/redis.conf - /path/to/redis-cluster/cluster2/follower/data:/data ports: - 6382:6379 networks: redisNet: ipv4_address: ip4 master3: image: redis:4.0.14-alpine container_name: redis-cluster3-master command: redis-server /etc/redis/redis.conf stdin_open: true tty: true volumes: - /path/to/redis-cluster/cluster3/master/redis.conf:/etc/redis/redis.conf - /path/to/redis-cluster/cluster3/master/data:/data ports: - 6383:6379 networks: redisNet: ipv4_address: ip5 follow3: image: redis:4.0.14-alpine container_name: redis-cluster3-follower command: redis-server /etc/redis/redis.conf stdin_open: true tty: true volumes: - /path/to/redis-cluster/cluster3/follower/redis.conf:/etc/redis/redis.conf - /path/to/redis-cluster/cluster3/follower/data:/data ports: - 6384:6379 networks: redisNet: ipv4_address: ip6 networks: redisNet: external: true
使用external docker网络
启动 docker-compose up -d
停止 docker-compose down
启动成功后,通过redis-cli命令创建集群
redis-cli --cluster create --cluster-replicas 1 ip1:6379 ip2:6379 ip3:6379 ip4:6379 ip5:6379 ip6:6379
此命令默认以ip1,ip3,ip5作为master节点,ip2,ip4,ip6作为slave节点创建三个主从节点的cluster
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)