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

时间:2019-08-12 15:54:16

标签: docker redis docker-compose redis-sentinel

我正在使用以下配置启动Redis和哨兵节点。我首先启动redis节点,当我启动Sentinel时,如果失败并显示错误:

product variants

Redis撰写

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_startup.sh

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-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

redis节点启动无误。

3 个答案:

答案 0 :(得分:0)

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

MatserRedis文件中sentinel.conf的拼写也令人怀疑。

答案 1 :(得分:0)

我认为您必须公开端口,如下所示:

expose:
      - 6379

对于 redis 实例,像这样:

expose:
      - 26379

对于哨兵实例。

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

答案 2 :(得分:0)

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

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