【问题标题】:redis-sentinel throws error: " Can't resolve master instance hostname."redis-sentinel 抛出错误:“无法解析主实例主机名。”
【发布时间】:2019-12-19 05:24:27
【问题描述】:

我正在使用以下配置启动 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"]

sentinel 启动脚本

redis-server /etc/sentinel_node.conf --sentinel

哨兵会议

sentinel monitor MatserRedis redis_node 6000 3
sentinel down-after-milliseconds MatserRedis 3000
sentinel failover-timeout MatserRedis 10000
sentinel parallel-syncs MatserRedis 1

redis节点启动正常

【问题讨论】:

    标签: docker redis docker-compose redis-sentinel


    【解决方案1】:

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

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

    更多详情,请查看 Redis 文档中的IP Addresses and DNS names

    【讨论】:

    • 非常感谢。我没有启用这个并且有同样的问题。现在它正在工作......
    【解决方案2】:

    使用最新的 redis 版本,您只需将“sentinel resolve-hostnames yes”添加到 sentinel.conf。一切都像魅力一样。

    参考:https://redis.io/topics/sentinel

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        【解决方案4】:

        我认为您必须像这样公开端口:

        expose:
              - 6379
        

        对于 redis 实例,如下所示:

        expose:
              - 26379
        

        用于哨兵实例。

        更重要的是,您必须将相同的 docker 网络连接到两个撰写文件!

        【讨论】:

          猜你喜欢
          • 2022-06-16
          • 1970-01-01
          • 1970-01-01
          • 2018-07-03
          • 1970-01-01
          • 2022-07-18
          • 2014-11-13
          • 2017-03-26
          • 2011-05-20
          相关资源
          最近更新 更多