采用三台主节点 Docker部署,均采用默认端口,每台机器一台redis,可以视情况自行修改
# 清理环境,所有节点执行! 注意会删除数据
rm -rf /opt/redis/cluster
mkdir -p /opt/redis/cluster/{conf,data}
cd /opt/redis/cluster/conf
wget http://download.redis.io/redis-stable/redis.conf
docker stop redis
docker rm redis
# 以下参数均可以在配置文件配置,这里配置优先级更高!
#1号机器执行
docker run -p 6379:6379 -p 16379:16379 --name redis \
-v /opt/redis/cluster/conf/redis.conf:/etc/redis/redis.conf \
-v /opt/redis/cluster/data:/data \
-d --hostname redis redis:latest redis-server /etc/redis/redis.conf \
--bind 0.0.0.0 \
--databases 5 \
--requirepass <YOUR_PASSWORD> \
--appendonly yes \
--cluster-enabled yes \
--cluster-node-timeout 5000 \
--cluster-require-full-coverage no \
--cluster-announce-ip <机器1IP>
#2号机器执行
docker run -p 6379:6379 -p 16379:16379 --name redis \
-v /opt/redis/cluster/conf/redis.conf:/etc/redis/redis.conf \
-v /opt/redis/cluster/data:/data \
-d --hostname redis redis:latest redis-server /etc/redis/redis.conf \
--bind 0.0.0.0 \
--databases 5 \
--appendonly yes \
--requirepass <YOUR_PASSWORD> \
--cluster-enabled yes \
--cluster-node-timeout 5000 \
--cluster-require-full-coverage no \
--cluster-announce-ip <机器2IP>
#3号机器执行
docker run -p 6379:6379 -p 16379:16379 --name redis \
-v /opt/redis/cluster/conf/redis.conf:/etc/redis/redis.conf \
-v /opt/redis/cluster/data:/data \
-d --hostname redis redis:latest redis-server /etc/redis/redis.conf \
--bind 0.0.0.0 \
--databases 5 \
--appendonly yes \
--requirepass <YOUR_PASSWORD> \
--cluster-enabled yes \
--cluster-node-timeout 5000 \
--cluster-require-full-coverage no \
--cluster-announce-ip <机器3IP>
# 随便一个节点执行,如果你想更多的节点加入,可以修改replicas数量,例如在6台redis服务器情况下,replicas=1则会默认分配3主3从的环境
docker exec -it redis redis-cli -p 6379 -a <YOUR_PASSWORD> --cluster create --cluster-replicas 0 <机器1IP>:6379 <机器2IP>:6379 <机器3IP>:6379
其他说明
- cluster-announce-ip
- cluster-announce-port
- cluster-announce-tls-port
- cluster-announce-bus-port 这四个参数是redis专门为docker环境下提供的,避免ip或者端口指向了默认的错误地址、内网地址等
- cluster-require-full-coverage no 集群有宕机时其他机器仍然可用,但是请注意如果hash槽落到了不可用机器上,命令将失败
- requirepass 密码必须一致
\
标签:opt,6379,--,redis,cluster,集群,conf,docker From: https://www.cnblogs.com/JuneQS/p/16612532.html