docker - redis-sentinel 抛出错误 : "Can' t resolve master instance hostname.“

标签 docker redis docker-compose redis-sentinel

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

相关文章:

django - 从Docker包含Django App访问Windows定位的Firebird数据库

mongodb - 如何将Mongo docker容器连接到主机上安装的mongodb compass社区

java - 用于 Spring Boot 的嵌入式 Redis

ruby - 使用ruby删除redis键匹配模式

尽管在多个文件中使用 ifndef,C++ 多重定义

Docker compose 环境变量未在 nginx 中获取

linux - 以退出代码2退出的Docker容器 “sh can' t open 'start_script.sh':没有这样的文件或目录”

docker - 重新启动后 Google Cloud Logging 驱动程序找不到凭据

docker - Dockerfile Entrypoint似乎是追加而不是覆盖

mongodb - 完成入口点脚本后停止容器