redis-sentinel throws error: " Can't resolve master instance hostname."
Asked Answered
R

4

14

I'm starting up redis and sentinel nodes using the below configurations. I start the redis node first and when I start Sentinel, if fails with the error:

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

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

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

sentinel conf

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

The redis node starts up without error.

Riebling answered 12/8, 2019 at 15:54 Comment(0)
S
28

Only sentinel with version above 6.2 can resolve host names, but this is not enabled by default. Adding sentinel resolve-hostnames yes to sentinel.conf will help.

If your sentinel has older versions, the hostname redis_node should be replaced by and ip.

For more details, check out IP Addresses and DNS names in Redis document

Scapegoat answered 9/9, 2021 at 8:0 Comment(1)
Thanks a lot. I didn't enable this and having same issues. now it's working...Pye
C
4

With the latest redis version, you simply add "sentinel resolve-hostnames yes" to sentinel.conf. Everything works like a charm.

Ref: https://redis.io/topics/sentinel

Canine answered 25/5, 2021 at 18:45 Comment(0)
J
-3

I think it's probably because redis_node doesn't resolve to an IP address. Perhaps try putting the IP address in sentinel.conf instead.

The spelling of MatserRedis in the sentinel.conf file looks questionable too.

Jaysonjaywalk answered 5/9, 2019 at 16:13 Comment(0)
M
-3

I think you have to expose the ports, like this:

expose:
      - 6379

for the redis instance and like this:

expose:
      - 26379

for the sentinel instance.

More importantly, you have to have the same docker network attached to both compose files!

Managerial answered 20/1, 2021 at 13:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.