docker部署redis集群(实战)

集群的话我们要建立自己的网卡。

创建多个节点(实例是6个三个主三个从):

创建挂载目录:

for port in $(seq 1 6); \

do \

mkdir -p /mydata/redis/node-${port}/conf

touch /mydata/redis/node-${port}/conf/redis.conf

cat << EOF >/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 172.38.0.1${port}

cluster-announce-port 6379

cluster-announce-bus-port 16379

appendonly yes

EOF

done

创建容器

for port in $(seq 1 6); \

do \

docker run -p 637${port}:6379 -p 1637${port}:16379 --name redis-${port} \

-v /mydata/redis/node-${port}/data:/data \

-v /mydata/redis/node-${port}/conf/redis.conf:/etc/redis/redis.conf \

-d --net redis-net --ip 172.38.0.1${port} redis:5.0.9-alpine3.11 redis-server  /etc/redis/redis.conf;

done

创建集群:

先进入:

docker exec -it redis-1 /bin/sh

集群:

redis-cli --cluster create 172.38.0.11:6379 172.38.0.12:6379 172.38.0.13:6379 172.38.0.14:6379 172.38.0.15:6379 172.38.0.16:6379 --cluster-replicas 1

redis中没有bash命令有sh命令/bin/sh

你可能感兴趣的:(docker部署redis集群(实战))