三主三从的Redis 出现了,在外部无法分配key到其他主节点的情况(本机上没有任何问题),由于项目着急上线,目前使用一主一从的配置,具体配置情况如下。
dockerfile
FROM redis
COPY redis.conf /usr/local/etc/redis/redis.conf
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]
主节点的redis 配置
bind 0.0.0.0
port 6379
daemonize yes
pidfile /root/redis/redis_6379.pid
#cluster-enabled yes // 必须注掉这行,要不默认是配置集群的
cluster-config-file nodes_6379.conf
cluster-node-timeout 15000
appendonly yes
从节点的配置
#bind 0.0.0.0 从节点必须注掉这行,要不连接不到外面
port 6380
daemonize yes
pidfile /root/redis/redis_6380.pid
#cluster-enabled yes
cluster-config-file nodes_6380.conf
cluster-node-timeout 15000
appendonly yes
slaveof xx.xxx.xxx.xx(主节点的IP) 6379
分别用这两个 配置文件创建主的镜像 和从的镜像
启动容器,为了省去配置端口的麻烦可以使考虑使用 --net=host 这个配置启动容器,这样默认所有端口都能访问的。
这样一主一从的Redis 就配置完了。
如果没有启动成功的话 可以考虑进入容器重启redis 服务
redis-server /usr/local/etc/redis/redis.conf