基于docker-compose搭建哨兵模式集群
网上找了很多相关配置的文章,由于docker映射地址命令不熟,都没能成功启动。后来发现通过docker-compose的yml文件控制可以很好的解决这个问题。
注意要在配置好的docker-compose.yml文件夹下启动
>docker-compose.yml:
version: "3"
services:
redis1:
image: "redis"
container_name: redis1
restart: always
ports:
- "7001:6379"
environment:
- TZ=Asia/Shanghai
volumes:
- "./redis1.conf:/usr/local/redis/redis.conf"
- "./sentinel1.conf:/data/sentinel.conf" #此处填好已经写好的配置文件地址
- "./data:/data"
command: ["redis-server","/usr/local/redis/redis.conf"]
redis2:
image: "redis"
container_name: redis2
restart: always
ports:
- "7002:6379"
environment:
- TZ=Asia/Shanghai
volumes:
- "./redis2.conf:/usr/local/redis/redis.conf"
- "./sentinel2.conf:/data/sentinel.conf"
- "./data:/data"
command: ["redis-server","/usr/local/redis/redis.conf"]
redis3:
image: "redis"
container_name: redis3
restart: always
ports:
- "7003:6379"
environment:
- TZ=Asia/Shanghai
volumes:
- "./redis3.conf:/usr/local/redis/redis.conf"
- "./sentinel3.conf:/data/sentinel.conf"
- "./data:/data"
command: ["redis-server","/usr/local/redis/redis.conf"]
>三个哨兵配置文件:
主节点:
#哨兵需要后台启动
daemonize no
# master节点的ip和端口,主节点的配置
sentinel monitor master localhost 6379 1
#哨兵每隔10秒监听一次
sentinel down-after-milliseconds master 10000
从(两个从节点一样):
#哨兵需要后台启动
daemonize no
#哨兵每隔10秒监听一次
# master节点的ip和端口,从节点的配置
sentinel monitor master 192.168.220.66 6379 1
sentinel down-after-milliseconds master 10000