1、創(chuàng)建一個(gè)自己的網(wǎng)卡
docker network create redis --subnet 192.167.0.0/24
2、腳本創(chuàng)建集群
for port in {port}/conf
touch /mydata/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 192.167.0.1${port}
cluster-announce-port 6379
cluster-announce-bus-port 16379
appendonly yes
EOF
done
接著啟動(dòng)6個(gè)redis
for port in {port}:6379 -p 1637{port}
-v /mydata/redis/node-{port}/conf/redis.conf:/etc/redis/redis.conf
-d --net redis --ip 192.167.0.1${port} redis redis-server /etc/redis/redis.conf;
done
接著隨便進(jìn)入一個(gè)redis容器
docker exec -it redis-1 /bin/sh
創(chuàng)建redis集群
redis-cli --cluster create 192.167.0.11:6379 192.167.0.12:6379 192.167.0.13:6379 192.167.0.14:6379 192.167.0.15:6379 192.167.0.16:6379 --cluster-replicas 1