(相关资料图)
单机部署
docker pull redis: run -d -p 6379:6379 --name \--privileged=true --restart=always \-v /opt/docker//conf/:/etc/redis/ \-v /opt/docker//data:/data redis: \redis-server /etc/redis/
集群部署(3主3从)
1、准备6份配置文件,根据实际情况修改
#port(端口号)port ${PORT}#masterauth(设置集群节点间访问密码,跟下面一致)masterauth 123456#requirepass(设置redis访问密码)requirepass 123456#cluster-enabled yes(启动集群模式)cluster-enabled yes#cluster-config-file (集群节点信息文件)cluster-config-file #cluster-node-timeout 5000(redis节点宕机被发现的时间)cluster-node-timeout 5000#cluster-announce-ip(集群节点的汇报ip,防止nat,预先填写为网关ip后续需要手动修改配置文件)cluster-announce-ip #cluster-announce-port(集群节点的汇报port,防止nat)cluster-announce-port ${PORT}#cluster-announce-bus-port(集群节点的汇报bus-port,防止nat)cluster-announce-bus-port 1${PORT}#appendonly yes(开启aof) appendonly yes
2、启动6个镜像
docker run -d --net=host \-v /home/fzp_ms/docker/redis/7379/conf/:/etc/redis/ \-v /home/fzp_ms/docker/redis/7379/data:/data \--restart always --privileged=true --name=redis-7379 redis: redis-server /etc/redis/ run -d --net=host \-v /home/fzp_ms/docker/redis/7380/conf/:/etc/redis/ \-v /home/fzp_ms/docker/redis/7380/data:/data \--restart always --privileged=true --name=redis-7380 redis: redis-server /etc/redis/ run -d --net=host \-v /home/fzp_ms/docker/redis/7381/conf/:/etc/redis/ \-v /home/fzp_ms/docker/redis/7381/data:/data \--restart always --privileged=true --name=redis-7381 redis: redis-server /etc/redis/ run -d --net=host \-v /home/fzp_ms/docker/redis/7382/conf/:/etc/redis/ \-v /home/fzp_ms/docker/redis/7382/data:/data \--restart always --privileged=true --name=redis-7382 redis: redis-server /etc/redis/ run -d --net=host \-v /home/fzp_ms/docker/redis/7383/conf/:/etc/redis/ \-v /home/fzp_ms/docker/redis/7383/data:/data \--restart always --privileged=true --name=redis-7383 redis: redis-server /etc/redis/ run -d --net=host \-v /home/fzp_ms/docker/redis/7384/conf/:/etc/redis/ \-v /home/fzp_ms/docker/redis/7384/data:/data \--restart always --privileged=true --name=redis-7384 redis: redis-server /etc/redis/
3、进入其中一台要设定master的节点docker容器中,执行初始化命令
# 进入容器docker exec -it 2cd952c5a343 bash# 在容器内执行初始化命令redis-cli -a sundun --cluster create --cluster-replicas 1