Docker搭建redis集群
1.创建虚拟网卡2.通过脚本创建6个redis配置3.进入容器创建集群4.连接集群查看集群
1.创建虚拟网卡
docker network create redis --subnet 172.38.0.0/16
8b1d0469809421a821079f74e9de5e3bb37257e81b03e7276156564f9add1122
docker network
ls
NETWORK ID NAME DRIVER SCOPE
b5dc3b970355 bridge bridge local
8f2cd56d3d7a host host local
6cf585b80b32 none null local
8b1d04698094 redis bridge local
2.通过脚本创建6个redis配置
for port
in `seq 1 6`;\
do \
mkdir -p /redisdata/redis/node-
${port}/conf
touch /redisdata/redis/node-
${port}/conf/redis.conf
cat << EOF
>/redisdata/redis/node-
${port}/conf/redis.conf
port 6379
bind 0.0.0.0
cluster-enabled
yes
cluster-config-file nodes.conf
cluster-announce-ip 172.38.0.1
${port}
cluster-announce-port 6379
cluster-announce-bus-port 16379
appendonly
yes
EOF
docker run -p 637
${port}:6379 -p 1637
${port}:16379 --name redis-
${port} \
-v /redisdata/redis/node-
${port}/data:/data \
-v /redisdata/redis/node-
${port}/conf/redis.conf:/etc/redis/redis.conf \
-d --network redis --ip 172.38.0.1
${port} redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
; \
done
3.进入容器创建集群
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
4.连接集群查看集群
/data
127.0.0.1:6379
> CLUSTER NODES
7fecd5c591884301d46baa2ae6ecf103d4a9e7d2 172.38.0.16:6379@16379 slave cd0bf96ccdfa3e876081ec0d3d1a8e285bb78dc4 0 1599099113348 6 connected
16bd9e562436f149926470e1f862e33dd4f0be70 172.38.0.15:6379@16379 slave 1fe38e4dcd5e85b7d9a1b62135f1dd64db9bf7c2 0 1599099115357 5 connected
1fe38e4dcd5e85b7d9a1b62135f1dd64db9bf7c2 172.38.0.11:6379@16379 myself,master - 0 1599099113000 1 connected 0-5460
cd0bf96ccdfa3e876081ec0d3d1a8e285bb78dc4 172.38.0.12:6379@16379 master - 0 1599099114352 2 connected 5461-10922
eb94ef7939631fd561cd0e4dd2c8e44b3693ea80 172.38.0.14:6379@16379 slave aba1c566bdfe413be0cf5e855abeda62b0c8b2d3 0 1599099112000 4 connected
aba1c566bdfe413be0cf5e855abeda62b0c8b2d3 172.38.0.13:6379@16379 master - 0 1599099112344 3 connected 10923-16383