所以我有这种 docker-compose
version: '3.8'
x-base: &base
image: redis:latest
x-base-sen: &base-sen
image: redis:latest
command: redis-sentinel /sentinel/sentinel.conf --protected-mode no
services:
redis1:
<<: *base
hostname: redis1
container_name: redis-master
command: redis-server --replica-announce-ip redis1 --slave-announce-ip redis1 --protected-mode no
redis2:
<<: *base
hostname: redis2
container_name: redis-slave1
command: redis-server --slaveof redis1 6379 --replica-announce-ip redis2 --slave-announce-ip redis2 --protected-mode no
redis3:
<<: *base
hostname: redis3
container_name: redis-slave2
command: redis-server --slaveof redis1 6379 --replica-announce-ip redis3 --slave-announce-ip redis3 --protected-mode no
sentinel1:
<<: *base-sen
hostname: sentinel1
container_name: redis-sentinel1
volumes:
- ./sentinel1:/sentinel
depends_on:
- redis1
- redis2
- redis3
sentinel2:
<<: *base-sen
hostname: sentinel2
container_name: redis-sentinel2
volumes:
- ./sentinel2:/sentinel
depends_on:
- redis1
- redis2
- redis3
sentinel3:
<<: *base-sen
hostname: sentinel3
container_name: redis-sentinel3
volumes:
- ./sentinel3:/sentinel
depends_on:
- redis1
- redis2
- redis3
这是我的 sentinel.conf 文件
port 26379
dir "/tmp"
sentinel monitor redismaster redis1 6379 2
sentinel down-after-milliseconds redismaster 3000
sentinel failover-timeout redismaster 6000
sentinel resolve-hostnames yes
sentinel announce-hostnames yes
sentinel announce-ip "sentinel1"
并且每个容器都有不同的配置文件和sentinel1
更改。因此,当我手动关闭主节点时,我希望哨兵选择其中一个从属节点作为新的主节点,但我收到这种日志,这是我的哨兵日志之一:
1:X 11 Jul 2022 19:13:23.693 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:X 11 Jul 2022 19:13:23.693 # Redis version=7.0.2, bits=64, commit=00000000, modified=0, pid=1, just started
1:X 11 Jul 2022 19:13:23.693 # Configuration loaded
1:X 11 Jul 2022 19:13:23.693 * monotonic clock: POSIX clock_gettime
1:X 11 Jul 2022 19:13:23.694 * Running mode=sentinel, port=26379.
1:X 11 Jul 2022 19:13:23.746 * Sentinel new configuration saved on disk
1:X 11 Jul 2022 19:13:23.746 # Sentinel ID is e12e36307bfb32bf091d20548edbb89b7b54feea
1:X 11 Jul 2022 19:13:23.746 # +monitor master redismaster redis1 6379 quorum 2
1:X 11 Jul 2022 19:13:23.747 * +slave slave redis2:6379 redis2 6379 @ redismaster redis1 6379
1:X 11 Jul 2022 19:13:23.801 * Sentinel new configuration saved on disk
1:X 11 Jul 2022 19:13:23.802 * +slave slave redis3:6379 redis3 6379 @ redismaster redis1 6379
1:X 11 Jul 2022 19:13:23.848 * Sentinel new configuration saved on disk
1:X 11 Jul 2022 19:13:24.192 * +sentinel sentinel 25ae390f472f4768b498cac40828e5f437eb393d sentinel3 26379 @ redismaster redis1 6379
1:X 11 Jul 2022 19:13:24.270 * Sentinel new configuration saved on disk
1:X 11 Jul 2022 19:13:24.572 * +sentinel sentinel 924b19cc7ef47d57e794ff1a87151fbf02451729 sentinel2 26379 @ redismaster redis1 6379
1:X 11 Jul 2022 19:13:24.636 * Sentinel new configuration saved on disk
1:X 11 Jul 2022 19:16:03.202 # Failed to resolve hostname 'redis1'
1:X 11 Jul 2022 19:16:03.202 # +tilt #tilt mode entered
1:X 11 Jul 2022 19:16:13.213 # Failed to resolve hostname 'redis1'
1:X 11 Jul 2022 19:16:23.224 # Failed to resolve hostname 'redis1'
1:X 11 Jul 2022 19:16:33.234 # Failed to resolve hostname 'redis1'
这是其中一个从属节点的日志:
1:S 11 Jul 2022 19:13:18.197 * Successful partial resynchronization with master.
1:S 11 Jul 2022 19:13:18.197 * MASTER <-> REPLICA sync: Master accepted a Partial Resynchronization.
1:S 11 Jul 2022 19:15:50.125 # Connection with master lost.
1:S 11 Jul 2022 19:15:50.125 * Caching the disconnected master state.
1:S 11 Jul 2022 19:15:50.125 * Reconnecting to MASTER redis1:6379
1:S 11 Jul 2022 19:15:50.125 * MASTER <-> REPLICA sync started
1:S 11 Jul 2022 19:15:50.125 # Error condition on socket for SYNC: Connection refused
1:S 11 Jul 2022 19:15:50.970 * Connecting to MASTER redis1:6379
1:S 11 Jul 2022 19:16:00.980 # Unable to connect to MASTER: Resource temporarily unavailable
1:S 11 Jul 2022 19:16:01.983 * Connecting to MASTER redis1:6379
1:S 11 Jul 2022 19:16:11.994 # Unable to connect to MASTER: Resource temporarily unavailable
1:S 11 Jul 2022 19:16:12.997 * Connecting to MASTER redis1:6379
1:S 11 Jul 2022 19:16:23.007 # Unable to connect to MASTER: Resource temporarily unavailable
答案1
你可以看到我的 repo,其中 sentinels 功能已完全正常运行https://github.com/helderjnpinto/Redis-Sentinel-Docker-Compose只需执行 docker-compose up