前言
本小节我们学习一下使用Dokcer部署Redis集群之后为确保Redis HA性能实现Sentinel模式。
如何使用Docker部署Redis集群。
案例
参照前文,假设你已经成功部署了Redis集群。
-
目录参考
[root@iZ2ze8sm5upgi8z1dcazqeZ redis]# tree . ├── data │ ├── appendonly.aof │ ├── docker-compose.yml │ └── dump.rdb └── sentinel ├── config │ ├── docker-compose.yml │ ├── sentinel1.conf │ ├── sentinel2.conf │ ├── sentinel3.conf │ └── sentinel.conf └── data 4 directories, 8 files [root@iZ2ze8sm5upgi8z1dcazqeZ redis]#
-
在中workspace/redis/sentinel/config编写sentinel.conf文件
port 26379 dir /workspace/redis/sentinel/config # 自定义集群名,其中 182.92.0.228 为 redis-master 的 ip,6379 为 redis-master 的端口,2 为最小投票数(因为有 3 台 Sentinel 所以可以设置成 2) sentinel monitor redis-master 182.92.0.228 6379 2 sentinel down-after-milliseconds redis-master 30000 sentinel parallel-syncs redis-master 1 sentinel auth-pass redis-master Dustyone sentinel failover-timeout redis-master 180000 sentinel deny-scripts-reconfig yes
-
将sentinel.conf复制三份,复制文件与sentinel.conf同路径
cp sentinel.conf sentinel1.conf cp sentinel.conf sentinel2.conf cp sentinel.conf sentinel3.conf
-
编写docker-composr.yml
version: '3.7' services: sentinel1: image: redis container_name: redis-sentinel-1 command: redis-sentinel /workspace/redis/sentinel/config/sentinel.conf restart: always ports: - 26379:26379 volumes: - /workspace/redis/sentinel/config/sentinel1.conf:/workspace/redis/sentinel/config/sentinel.conf sentinel2: image: redis container_name: redis-sentinel-2 command: redis-sentinel /workspace/redis/sentinel/config/sentinel.conf restart: always ports: - 26380:26380 volumes: