我正在使用以下配置启动 redis 和哨兵节点。我首先启动 redis 节点,当我启动 Sentinel 时,如果失败并出现错误:
sentinel_node |
sentinel_node | *** FATAL CONFIG FILE ERROR ***
sentinel_node | Reading the configuration file, at line 1
sentinel_node | >>> 'sentinel monitor MasterRedis redis_node 6000 3'
sentinel_node | Can't resolve master instance hostname.
sentinel_node exited with code 1
Redis 组合
version: '2.1'
services:
redis:
image: redis
container_name: redis_node
environment:
- ALLOW_EMPTY_PASSWORD=yes
ports:
- 6000:6000
volumes:
- ./redis_startup.sh:/usr/local/bin/redis_startup.sh
- ./redis_server_stop.sh:/usr/local/bin/redis_server_stop.sh
command: ["redis_startup.sh", "-port", "6000"]
redis_startup.sh
redis-server --port ${port:-6000}
哨兵撰写
version: '2.1'
services:
sentinel:
image: redis
container_name: sentinel_node
ports:
- 26379:26379
volumes:
# This is a read-only file on the host disk. It will be
# used to create a rw file in this image
- ./sentinel_node.conf:/usr/local/sentinel_node.conf
- ./sentinel_startup.sh:/usr/local/bin/sentinel_startup.sh
- ./redis_server_stop.sh:/usr/local/bin/redis_server_stop.sh
command: ["sentinel_startup.sh", "-port", "6000", "-name", "sentinel_node"]
哨兵启动脚本
redis-server /etc/sentinel_node.conf --sentinel
哨兵 session
sentinel monitor MatserRedis redis_node 6000 3
sentinel down-after-milliseconds MatserRedis 3000
sentinel failover-timeout MatserRedis 10000
sentinel parallel-syncs MatserRedis 1
redis节点启动无误
最佳答案
只有6.2以上版本的sentinel可以解析主机名,但默认不开启。将 sentinel resolve-hostnames yes
添加到 sentinel.conf
会有所帮助。
如果你的哨兵有旧版本,主机名 redis_node
应该替换为 ip。
有关更多详细信息,请查看 IP Addresses and DNS names在 Redis 文档中
关于docker - redis-sentinel 抛出错误 : "Can' t resolve master instance hostname.“,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57464443/