集群涉及到的源文件:
config/node*/redis.conf
执行命令
docker-compose -f docker-compose.yml up -d
sh start.sh
docker-compose.yml详细代码
version: '3.4'
services:
node1:
image: redis:5.0.5
container_name: redis-node1
restart: always
network_mode: "host"
# ports:
# - 6061:6061
# - 16061:16061
volumes:
- ./data/node1:/data
- ./config/node1:/usr/local/etc/redis
command:
redis-server /usr/local/etc/redis/redis.conf
node2:
image: redis:5.0.5
container_name: redis-node2
restart: always
network_mode: "host"
# ports:
# - 6062:6062
# - 16062:16062
volumes:
- ./data/node2:/data
- ./config/node2:/usr/local/etc/redis
command:
redis-server /usr/local/etc/redis/redis.conf
node3:
image: redis:5.0.5
container_name: redis-node3
restart: always
network_mode: "host"
# ports:
# - 6063:6063
# - 16063:16063
volumes:
- ./data/node3:/data
- ./config/node3:/usr/local/etc/redis
command:
redis-server /usr/local/etc/redis/redis.conf
node4:
image: redis:5.0.5
container_name: redis-node4
restart: always
network_mode: "host"
# ports:
# - 6064:6064
# - 16064:16064
volumes:
- ./data/node4:/data
- ./config/node4:/usr/local/etc/redis
command:
redis-server /usr/local/etc/redis/redis.conf
node5:
image: redis:5.0.5
container_name: redis-node5
restart: always
network_mode: "host"
# ports:
# - 6065:6065
# - 16065:16065
volumes:
- ./data/node5:/data
- ./config/node5:/usr/local/etc/redis
command:
redis-server /usr/local/etc/redis/redis.conf
node6:
image: redis:5.0.5
container_name: redis-node6
restart: always
network_mode: "host"
# ports:
# - 6066:6066
# - 16066:16066
volumes:
- ./data/node6:/data
- ./config/node6:/usr/local/etc/redis
command:
redis-server /usr/local/etc/redis/redis.conf
start.sh详细代码
#!/bin/bash
docker-compose up -d
sleep 20
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