本文最后更新于 2024年12月2日 晚上
准备存储卷
准备Sentinel配置文件
需要三份 sentinel.conf 配置文件,分别为:
- sentinel1.conf
- sentinel2.conf
- sentinel3.conf
配置文件内容:
1 2 3 4 5 6 7 8
| port 26379 dir /tmp
sentinel monitor mymaster 127.0.0.1 6379 2 sentinel down-after-milliseconds mymaster 30000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 180000 sentinel deny-scripts-reconfig yes
|
搭建Redis集群
创建文件: /usr/local/redis/docker-compose.yml
, 内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| version: '3.1' services: master: image: redis container_name: redis-master ports: - 6379:6379
slave1: image: redis container_name: redis-slave-1 ports: - 6380:6379 command: redis-server --slaveof redis-master 6379
slave2: image: redis container_name: redis-slave-2 ports: - 6381:6379 command: redis-server --slaveof redis-master 6379 sentinel1: image: redis container_name: redis-sentinel-1 ports: - 26379:26379 command: redis-sentinel /usr/local/etc/redis/sentinel.conf volumes: - ./conf/sentinel/sentinel1.conf:/usr/local/etc/redis/sentinel.conf
sentinel2: image: redis container_name: redis-sentinel-2 ports: - 26380:26379 command: redis-sentinel /usr/local/etc/redis/sentinel.conf volumes: - ./conf/sentinel/sentinel2.conf:/usr/local/etc/redis/sentinel.conf
sentinel3: image: redis container_name: redis-sentinel-3 ports: - 26381:26379 command: redis-sentinel /usr/local/etc/redis/sentinel.conf volumes: - ./conf/sentinel/sentinel3.conf:/usr/local/etc/redis/sentinel.conf
|
启动容器
启动容器:
查看集群是否生效
进入 Sentinel 容器,使用 Sentinel API 查看监控情况
1 2 3 4
| docker exec -it redis-sentinel-1 /bin/bash redis-cli -p 26379 sentinel master mymaster sentinel slaves mymaster
|