docker redis5 集群搭建

创建 redis-cluster.tmpl 配置文件,内容如下:

port ${PORT}
protected-mode no
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 192.168.1.200 # 改为自己的ip
cluster-announce-port ${PORT}
cluster-announce-bus-port 1${PORT}
appendonly yes

开始执行命令创建集群(最低6个节点,三个master,三个slave)

$ mkdir redis-cluster
$ cd redis-cluster
$ for port in `seq 7000 7005`; do \
  mkdir -p ./${port}/conf \
  && PORT=${port} envsubst < ./redis-cluster.tmpl > ./${port}/conf/redis.conf \
  && mkdir -p ./${port}/data; \
done

$ for port in `seq 7000 7005`; do \
  docker run -d -ti -p ${port}:${port} -p 1${port}:1${port} \
  -v /home/byg/software/docker/volumn/redis-cluster/${port}/conf/redis.conf:/usr/local/etc/redis/redis.conf \
  -v /home/byg/software/docker/volumn/redis-cluster/${port}/data:/data \
  --restart always --name redis-${port} --net redis-net \
  --sysctl net.core.somaxconn=1024 redis redis-server /usr/local/etc/redis/redis.conf; \
done

$ docker inspect redis-7000 redis-7001 redis-7002 redis-7003 redis-7004 redis-7005 | grep IPAddress
$ docker exec -it redis-7000 bash
redis-cli --cluster create \
172.20.0.2:7000 \
172.20.0.3:7001 \
172.20.0.4:7002 \
172.20.0.5:7003 \
172.20.0.6:7004 \
172.20.0.7:7005 \
--cluster-replicas 1

完成

参考

你可能感兴趣的:(开发总结)