1.创建配置文件
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 637${port}
bind 0.0.0.0
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 192.168.80.100
cluster-announce-port 637${port}
cluster-announce-bus-port 1637${port}
appendonly yes
EOF
done
2.启动容器
for port in $(seq 1 6); \
do
docker run -p 637${port}:637${port} -p 1637${port}:1637${port} --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 redis redis-server /etc/redis/redis.conf; \
done
3.进入容器
docker exec -it redis-1 /bin/sh
4.创建集群
192.168.80.100 为本机物理地址
redis-cli --cluster create 192.168.80.100:6371 192.168.80.100:6372 192.168.80.100:6373 192.168.80.100:6374 192.168.80.100:6375 192.168.80.100:6376 --cluster-replicas 1
5.进入redis
redis-cli -c -p 6371
6.查看详细信息
CLUSTER INFO
7.查看nodes
CLUSTER NODES
8. 设置值
set k1 v1
9. 关闭对应的容器
docker stop redis-3
10.要重新进入再次获取
get k1