当前位置:网站首页>Docker deploy redis cluster

Docker deploy redis cluster

2022-06-27 02:15:00 Operation and maintenance @ small soldier


One 、 establish redis_cluster bridge

docker network create redis_cluster --subnet=172.38.1.0/24 -o com.docker.network.bridge.name=redis_cluster
ifconfig redis_cluster

 Insert picture description here

Two 、 Start six containers

Two containers in a group , One master, One slave,master Hang up ,slave It's going to be master

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 # Start cluster mode  cluster-config-file nodes.conf # Cluster node information file  cluster-node-timeout 5000 #redis The time when the node outage was discovered  cluster-announce-ip 172.38.1.1${port} # Report of cluster nodes ip, prevent nat, Here is docker Containers IP cluster-announce-port 6379 # Report of cluster nodes port, prevent nat cluster-announce-bus-port 16379 # Report of cluster nodes bus-port, prevent nat appendonly yes # Turn on aof Persistence  EOF
#  Start at one time through script 6 individual redis Containers 
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_cluster --ip 172.38.1.1${port} redis:6.0 redis-server /etc/redis/redis.conf
done

3、 ... and 、 Create clusters

docker exec -it redis-1 bash
redis-cli --cluster create 172.38.1.11:6379 172.38.1.12:6379 172.38.1.13:6379 172.38.1.14:6379 172.38.1.15:6379 172.38.1.16:6379 --cluster-replicas 1
redis-cli -c	# Enter the cluster 
cluster info	# View cluster information 

 Insert picture description here

cluster nodes

 Insert picture description here

Four 、 Uninstall the cluster

for port in $(seq 1 6); do docker rm -f redis-${port}; done
rm -rf /mydata/redis

5、 ... and 、 Reference article

Docker Deploy Redis colony

原网站

版权声明
本文为[Operation and maintenance @ small soldier]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270209066711.html