redis-sentinel 抛出错误:“无法解析主实例主机名。”

Don*_*mmy 11 redis redis-sentinel docker docker-compose

我正在使用以下配置启动 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
Run Code Online (Sandbox Code Playgroud)

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"]
Run Code Online (Sandbox Code Playgroud)

redis_startup.sh

redis-server --port ${port:-6000}
Run Code Online (Sandbox Code Playgroud)

哨兵撰写

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"]
Run Code Online (Sandbox Code Playgroud)

哨兵启动脚本

redis-server /etc/sentinel_node.conf --sentinel
Run Code Online (Sandbox Code Playgroud)

哨兵会议

sentinel monitor MatserRedis redis_node 6000 3
sentinel down-after-milliseconds MatserRedis 3000
sentinel failover-timeout MatserRedis 10000
sentinel parallel-syncs MatserRedis 1
Run Code Online (Sandbox Code Playgroud)

redis节点启动没有报错。

kas*_*lew 23

只有6.2以上版本的sentinel可以解析主机名,但默认不启用。添加sentinel resolve-hostnames yessentinel.conf会有帮助。

如果您的哨兵有旧版本,则主机名redis_node应替换为 和 ip。

有关更多详细信息,请查看Redis 文档中的IP 地址和 DNS 名称


ric*_*ich -3

我认为这可能是因为redis_node无法解析为 IP 地址。也许尝试将 IP 地址放入 sentinel.conf 中。

MatserRedis文件中的拼写sentinel.conf看起来也有问题。