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?

3 Answers 3

2
+50

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.

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.

3
  • 2
    Please elaborate on how you think that would solve the question. Commented Sep 14, 2015 at 18:23
  • Done :) Hope this helps! Commented Sep 14, 2015 at 18:29
  • Sentinel config file should be writable. Sentinel will write information about current master, known slaves and known other sentinels in this file. Commented Apr 16, 2017 at 6:56

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.