systemcl start docker
docker run -d --name redis-node-1 --net host --privileged=true -v /temp/redis/share/redis-node-1:/data redis --cluster-enabled yes --appendonly yes --port 6381
docker run -d --name redis-node-2 --net host --privileged=true -v /temp/redis/share/redis-node-2:/data redis --cluster-enabled yes --appendonly yes --port 6382
docker run -d --name redis-node-3 --net host --privileged=true -v /temp/redis/share/redis-node-3:/data redis --cluster-enabled yes --appendonly yes --port 6383
docker run -d --name redis-node-4 --net host --privileged=true -v /temp/redis/share/redis-node-4:/data redis --cluster-enabled yes --appendonly yes --port 6384
docker run -d --name redis-node-5 --net host --privileged=true -v /temp/redis/share/redis-node-5:/data redis --cluster-enabled yes --appendonly yes --port 6385
docker run -d --name redis-node-6 --net host --privileged=true -v /temp/redis/share/redis-node-6:/data redis --cluster-enabled yes --appendonly yes --port 6386
# 进入redis-node-1节点
docker exec -it redis-node-1 /bin/bash
# 构建主从关系,以下的ip可以在宿主主机上通过ifconfig查看(ens33)
redis-cli --cluster create 192.168.126.129:6381 192.168.126.129:6382 192.168.126.129:6383 192.168.126.129:6384 192.168.126.129:6385 192.168.126.129:6386 --cluster-replicas 1
redis-cli -p 6381
cluster info
cluster nodes
只需要重新启动即可。
docker start 容器ID
redis-cli -p 6381 -c
FLUSHALL
redis-cli --cluster check 192.168.126.129:6381
#启动redis-node-1
docker start redis-node-1
(
#停止redis-node-1的命令
docker stop redis-node-1
)
#查看集群状态
cluster nodes
- 新建6387、6388两个节点+新建后启动+查看是否有8个节点
docker run -d --name redis-node-7 --net host --privileged=true -v /temp/redis/share/redis-node-7:/data redis --cluster-enabled yes --appendonly yes --port 6387
docker run -d --name redis-node-8 --net host --privileged=true -v /temp/redis/share/redis-node-8:/data redis --cluster-enabled yes --appendonly yes --port 6388
docker ps
docker exec -it redis-node-7 /bin/bash
# 6381相当于6387的引路人,将6387推荐进入集群
redis-cli --cluster add-node 192.168.126.129:6387 192.168.126.129:6381
redis-cli --cluster check 192.168.126.129:6387
redis-cli --cluster reshard 192.168.126.129:6381
redis-cli --cluster check 192.168.126.129:6387
# redis-cli --cluster add-node 192.168.126.129:6388 192.168.126.129:6387 --cluster-slave --cluster-master-id 主节点7容器ID
redis-cli --cluster add-node 192.168.126.129:6388 192.168.126.129:6387 --cluster-slave --cluster-master-id a7e68cb432df591df220ad76700ea6bb43093ddc
redis-cli --cluster check 192.168.126.129:6388
redis-cli --cluster check 192.168.126.129:6387
# redis-cli --cluster del-node 192.168.126.129:6388 容器ID
redis-cli --cluster del-node 192.168.126.129:6388 19ad55089a4443f5c17260311ab4ddc50d7981d2
redis-cli --cluster reshard 192.168.126.129:6381
redis-cli --cluster del-node 192.168.126.129:6387 容器ID