1.关闭防火墙、selinux
2.启动docker
systemctl start docker
3.保证可以连接互联网
docker network create redis --subnet 172.38.0.0/16
1)创建目录
mkdir -p /home/redis/node0{1…6}/data
2)编写 redis.conf 文件
vim /home/redis/node01/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.11
cluster-announce-bus-port 16379
appendonly yes
3)拷贝配置文件到其余节点目录
cd /home/redis/node01/
cp redis.conf …/node02/
cp redis.conf …/node03/
cp redis.conf …/node04/
cp redis.conf …/node05/
cp redis.conf …/node06/
4)修改各节点网络参数
vim …/node02/redis.conf
cluster-announce-ip 172.38.0.12
vim …/node03/redis.conf
cluster-announce-ip 172.38.0.13
vim …/node04/redis.conf
cluster-announce-ip 172.38.0.14
vim …/node05/redis.conf
cluster-announce-ip 172.38.0.15
vim …/node06/redis.conf
cluster-announce-ip 172.38.0.16
docker run --name redis01 -p 6371:6379 -p 16371:16379
-v /home/redis/node01/data:/data
-v /home/redis/node01/redis.conf:/etc/redis/redis.conf
-d --net redis --ip 172.38.0.11 redis redis-server /etc/redis/redis.conf
docker run --name redis02 -p 6372:6379 -p 16372:16379
-v /home/redis/node02/data:/data
-v /home/redis/node02/redis.conf:/etc/redis/redis.conf
-d --net redis --ip 172.38.0.12 redis redis-server /etc/redis/redis.conf
docker run --name redis03 -p 6373:6379 -p 16373:16379
-v /home/redis/node03/data:/data
-v /home/redis/node03/redis.conf:/etc/redis/redis.conf
-d --net redis --ip 172.38.0.13 redis redis-server /etc/redis/redis.conf
docker run --name redis04 -p 6374:6379 -p 16374:16379
-v /home/redis/node04/data:/data
-v /home/redis/node04/redis.conf:/etc/redis/redis.conf
-d --net redis --ip 172.38.0.14 redis redis-server /etc/redis/redis.conf
docker run --name redis05 -p 6375:6379 -p 16375:16379
-v /home/redis/node05/data:/data
-v /home/redis/node05/redis.conf:/etc/redis/redis.conf
-d --net redis --ip 172.38.0.15 redis redis-server /etc/redis/redis.conf
docker run --name redis06 -p 6376:6379 -p 16376:16379
-v /home/redis/node06/data:/data
-v /home/redis/node06/redis.conf:/etc/redis/redis.conf
-d --net redis --ip 172.38.0.16 redis redis-server /etc/redis/redis.conf
1)进入容器
docker exec -it redis01 /bin/bash
2)创建集群
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
1)停掉容器Redis03
docker stop redis03