1.配置文件
mkdir -p redis-cluster/7001/
mkdir -p redis-cluster/7002/
mkdir -p redis-cluster/7003/
mkdir -p redis-cluster/7004/
mkdir -p redis-cluster/7005/
mkdir -p redis-cluster/7006/
cd redis-cluster
vim 7001/redis.conf
bind 0.0.0.0
port 7001
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 30000
appendonly yes
protected-mode no
cp 7001/redis.conf 7002
cp 7001/redis.conf 7003
cp 7001/redis.conf 7004
cp 7001/redis.conf 7005
cp 7001/redis.conf 7006
vim 7002/redis.conf 把7001改成7002
vim 7003/redis.conf 把7001改成7003
vim 7004/redis.conf 把7001改成7004
vim 7005/redis.conf 把7001改成7005
vim 7006/redis.conf 把7001改成7006
2拉镜像
docker pull redis:5.0.5
3运行
docker run -d --name redis-7001 --net host -v /root/redis-cluster/7001/redis.conf:/usr/local/etc/redis/redis.conf redis:5.0.5 redis-server /usr/local/etc/redis/redis.conf
docker run -d --name redis-7002 --net host -v /root/redis-cluster/7002/redis.conf:/usr/local/etc/redis/redis.conf redis:5.0.5 redis-server /usr/local/etc/redis/redis.conf
docker run -d --name redis-7003 --net host -v /root/redis-cluster/7003/redis.conf:/usr/local/etc/redis/redis.conf redis:5.0.5 redis-server /usr/local/etc/redis/redis.conf
docker run -d --name redis-7004 --net host -v /root/redis-cluster/7004/redis.conf:/usr/local/etc/redis/redis.conf redis:5.0.5 redis-server /usr/local/etc/redis/redis.conf
docker run -d --name redis-7005 --net host -v /root/redis-cluster/7005/redis.conf:/usr/local/etc/redis/redis.conf redis:5.0.5 redis-server /usr/local/etc/redis/redis.conf
docker run -d --name redis-7006 --net host -v /root/redis-cluster/7006/redis.conf:/usr/local/etc/redis/redis.conf redis:5.0.5 redis-server /usr/local/etc/redis/redis.conf
4建redis集群
docker exec -it redis-7001 redis-cli --cluster create 121.40.27.205:7001 121.40.27.205:7002 121.40.27.205:7003 121.40.27.205:7004 121.40.27.205:7005 121.40.27.205:7006 --cluster-replicas 1
5查看是否成功建集群
docker exec -it redis-7001 bash
redis-cli -c -h 121.40.27.205 -p 7001
cluster nodes
cluster info