Redis Sentinelconfiguration和主机名

我有2个哨兵和2个Redis服务器。 我想使用redis服务器的主机名来configuration哨兵。 目前,我在这个主机文件中定义每个主机名。

10.22.20.156 clsupport1 10.22.20.157 clsupport2 

我尝试像这样configuration哨兵。

 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 

在我启动我的哨兵后,它会自动用IP地址replace主机名。 重启后。

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

但是我想保留主机名。 我怎样才能做到这一点?

Redis Sentinel需要dynamic地重写其configuration文件,重新创buildmonitor命令。 它没有规定在它生成的命令中插入主机名而不是IP地址。 这也是为什么Sentinel文档明确规定这个位置的IP地址的原因。

所以当前版本的Sentinel不能实现你所要求的。 我build议你重新评估使用configuration主机名的要求。

也许你可以尝试设置不可变标志到configuration文件。

 chattr +i configurationfile 

具有'i'属性的文件不能被修改:不能被删除或重命名,不能创build链接到这个文件,也没有数据可以被写入文件。 只有拥有CAP_LINUX_IMMUTABLE能力的超级用户或进程才能设置或清除该属性。

通过这种方式,您将写保护您的configuration文件。