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

Docker deploys a redis cluster

2022-06-10 14:20:00 java_ prinln

Docker Deploy a Redis colony

Fragmentation + High availability + Load balancing

 Insert picture description here

Create a network card

docker network create redis --subnet 172.38.0.0/16

Create six by script redis To configure

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

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 --ip 172.38.0.1${port} redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf; \


#  start-up 6 A container  
docker run -p 6371:6379 -p 16371:16379 --name redis-1 \ 
-v /mydata/redis/node-1/data:/data \ 
-v /mydata/redis/node-1/conf/redis.conf:/etc/redis/redis.conf \ 
-d --net redis --ip 172.38.0.11 redis:5.0.9-alpine3.11 redis-server
/etc/redis/redis.conf

docker run -p 6376:6379 -p 16376:16379 --name redis-6 \ 
-v /mydata/redis/node-6/data:/data \ 
-v /mydata/redis/node-6/conf/redis.conf:/etc/redis/redis.conf \ 
-d --net redis --ip 172.38.0.16 redis:5.0.9-alpine3.11 redis-server
 /etc/redis/redis.conf

Enter a redis, Notice that this is sh command

docker exec -it redis-1 /bin/sh

Create clusters

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

Connect clusters

redis-cli -c

View cluster information

cluster info

Look at the node

cluster nodes 

set a b
Stop to the value storage container
Then again, get a, It is found that the value can still be obtained
Look at the node , There is no problem finding high availability

原网站

版权声明
本文为[java_ prinln]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101335376531.html