2

I have 2 sentineles and 2 redis servers. I want to configure sentinels using hostnames of redis servers. Currently, I define each hostname in hosts file like this.

10.22.20.156    clsupport1  
10.22.20.157    clsupport2

And I try to configure sentinel like this.

daemonize yes
pidfile "/var/run/redis_sentinel_26379.pid"
loglevel notice
logfile "/var/log/redis_sentinel_26379.log"

port 26379
dir "/tmp"

sentinel monitor redis-prod clsupport2 6379 1
sentinel config-epoch redis-prod 3
sentinel leader-epoch redis-prod 4
sentinel known-slave redis-prod clsupport1 6379

After I started my sentinel, It automatically replaces hostnames with ip addresses. After restart.

daemonize yes
pidfile "/var/run/redis_sentinel_26379.pid"
loglevel notice
logfile "/var/log/redis_sentinel_26379.log"

port 26379
dir "/tmp"

sentinel monitor redis-prod 10.22.20.157 6379 1
sentinel config-epoch redis-prod 3
sentinel leader-epoch redis-prod 4
sentinel known-slave redis-prod 10.22.20.156 6379
# Generated by CONFIG REWRITE
...

But I want to keep hostnames. How can I achieve that?

bhdrkn
  • 73
  • 1
  • 8

3 Answers3

2

Redis Sentinel needs to dynamically rewrite its configuration file, recreating the monitor commands. It does not have provisions to insert host names instead of IP addresses in the commands it generates. This is also why the Sentinel documentation explicitly stipulates an IP address in this position.

So what you are asking for is not possible with the current version of Sentinel. I suggest you reassess the requirement to use hostnames for the configuration.

Tilman Schmidt
  • 3,778
  • 10
  • 23
0

Please just comment below or above the IP addresses.

redis-sentinel are designed to fetch the address of cluster nodes and update redis configurations once the status is changed. Your best chance is to write down the hostname with ip in the comment

-1

Maybe you can try to set immutable flag to the configuration file.

chattr +i configurationfile

A file with the 'i' attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.

In this way you will write-protect your configuration file.