docker 创建redis 集群 部署
1. 创建 网卡
docker network create redis --subnet 172.110.110.0/16
2. 使用脚本创建redis配置文件
for port in $(seq 1 6); \
do \
mkdir -p /root/redis/node-${port}/conf
touch /root/redis/node-${port}/conf/redis.conf
cat << EOF >/root/redis/node-${port}/conf/redis.conf
port 6379
bind 0.0.0.0
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 172.110.110.1${port}
cluster-announce-port 6379
cluster-announce-bus-port 16379
appendonly yes
EOF
done
3. 启动redis
docker run -p 6371:6379 -p 16371:16379 --name redis-1 -v /root/redis/node-1/data:/data -v /root/redis/node-1/conf/redis.conf:/etc/redis/redis.conf -d --net redis --ip 172.110.110.11 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
docker run -p 6372:6379 -p 16372:16379 --name redis-2 -v /root/redis/node-2/data:/data -v /root/redis/node-2/conf/redis.conf:/etc/redis/redis.conf -d --net redis --ip 172.110.110.12 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
docker run -p 6373:6379 -p 16373:16379 --name redis-3 -v /root/redis/node-3/data:/data -v /root/redis/node-3/conf/redis.conf:/etc/redis/redis.conf -d --net redis --ip 172.110.110.13 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
docker run -p 6374:6379 -p 16374:16379 --name redis-4 -v /root/redis/node-4/data:/data -v /root/redis/node-4/conf/redis.conf:/etc/redis/redis.conf -d --net redis --ip 172.110.110.14 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
docker run -p 6375:6379 -p 16375:16379 --name redis-5 -v /root/redis/node-5/data:/data -v /root/redis/node-5/conf/redis.conf:/etc/redis/redis.conf -d --net redis --ip 172.110.110.15 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
docker run -p 6376:6379 -p 16376:16379 --name redis-6 -v /root/redis/node-6/data:/data -v /root/redis/node-6/conf/redis.conf:/etc/redis/redis.conf -d --net redis --ip 172.110.110.16 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
4. 进入redis
docker exec -it redis-1 /bin/sh
4. 创建集群
redis-cli --cluster create 172.110.110.11:6379 172.110.110.12:6379 172.110.110.13:6379 172.110.110.14:6379 172.110.110.15:6379 172.110.110.16:6379 --cluster-replicas 1