Redis-sentinel抛出错误:"无法解析主实例的主机名。"

10

我正在使用以下配置启动Redis和Sentinel节点。我先启动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 Compose(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}

sentinel compose

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配置文件

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

Redis节点启动无误。

4个回答

20

只有版本高于6.2的sentinel才能解析主机名,但这不是默认启用的。在sentinel.conf中添加sentinel resolve-hostnames yes可以帮助解决问题。

如果你的sentinel版本较旧,则应将主机名redis_node替换为IP地址。

更多详情请查看Redis文档中关于IP地址和DNS名称的内容。


非常感谢。我之前没有启用它,也遇到了同样的问题。现在它已经可以工作了... - atiq1589

4

在最新的Redis版本中,您只需将“sentinel resolve-hostnames yes”添加到sentinel.conf中即可。一切都像魔法般地工作。

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


-3

我认为您需要暴露端口,像这样:

expose:
      - 6379

对于 Redis 实例,可以像这样:

expose:
      - 26379

针对哨兵实例。

更重要的是,您必须将相同的Docker网络附加到两个组合文件中!


-3

我认为可能是因为redis_node没有解析为IP地址。也许尝试在sentinel.conf中放置IP地址会更好。

sentinel.conf文件中MatserRedis的拼写看起来也很可疑。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接