一、创建Redis网络
docker network ls docker network create redis --subnet 192.168.100.0/24 docker network inspect redis
二、创建Redis配置文件
for port in $(seq 1 6); \ do \ mkdir -p /docker-volume/redis-cluster/node-${port}/conf touch /docker-volume/redis-cluster/node-${port}/conf/redis.conf cat << EOF >/docker-volume/redis-cluster/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 192.168.100.1${port} cluster-announce-port 6379 cluster-announce-bus-port 16379 appendonly yes EOF done
三、启动Redis容器
# 第一个节点配置命令 docker run -p 6371:6379 -p 16371:16379 --name redis-01 \ -v /docker-volume/redis-cluster/node-1/data:/data \ -v /docker-volume/redis-cluster/node-1/conf/redis.conf:/etc/redis/redis.conf \ -d --net redis --ip 192.168.100.11 --privileged=true redis:6.0.8 redis-server /etc/redis/redis.conf # 第二个节点配置命令 docker run -p 6372:6379 -p 16372:16379 --name redis-02 \ -v /docker-volume/redis-cluster/node-2/data:/data \ -v /docker-volume/redis-cluster/node-2/conf/redis.conf:/etc/redis/redis.conf \ -d --net redis --ip 192.168.100.12 --privileged=true redis:6.0.8 redis-server /etc/redis/redis.conf # 第三个节点配置命令 docker run -p 6373:6379 -p 16373:16379 --name redis-03 \ -v /docker-volume/redis-cluster/node-3/data:/data \ -v /docker-volume/redis-cluster/node-3/conf/redis.conf:/etc/redis/redis.conf \ -d --net redis --ip 192.168.100.13 --privileged=true redis:6.0.8 redis-server /etc/redis/redis.conf # 第四个节点配置命令 docker run -p 6374:6379 -p 16374:16379 --name redis-04 \ -v /docker-volume/redis-cluster/node-4/data:/data \ -v /docker-volume/redis-cluster/node-4/conf/redis.conf:/etc/redis/redis.conf \ -d --net redis --ip 192.168.100.14 --privileged=true redis:6.0.8 redis-server /etc/redis/redis.conf # 第五个节点配置命令 docker run -p 6375:6379 -p 16375:16379 --name redis-05 \ -v /docker-volume/redis-cluster/node-5/data:/data \ -v /docker-volume/redis-cluster/node-5/conf/redis.conf:/etc/redis/redis.conf \ -d --net redis --ip 192.168.100.15 --privileged=true redis:6.0.8 redis-server /etc/redis/redis.conf # 第六个节点配置命令 docker run -p 6376:6379 -p 16376:16379 --name redis-06 \ -v /docker-volume/redis-cluster/node-6/data:/data \ -v /docker-volume/redis-cluster/node-6/conf/redis.conf:/etc/redis/redis.conf \ -d --net redis --ip 192.168.100.16 --privileged=true redis:6.0.8 redis-server /etc/redis/redis.conf
四、创建Redis集群
docker exec -it redis-01 bash redis-cli --cluster create 192.168.100.11:6379 192.168.100.12:6379 192.168.100.13:6379 192.168.100.14:6379 192.168.100.15:6379 192.168.100.16:6379 --cluster-replicas 1
五、查看Redis集群
# 进入集群 redis-cli -c # 查看集群内节点 cluster nodes
标签:node,--,Redis,redis,cluster,集群,conf,Docker,docker From: https://www.cnblogs.com/Kevin-ZhangCG/p/18057625