在部署redis哨兵模式集群时,因为需要sentinel进行监控redis进行进行master节点转移,刚装好后,发现确实集群正常了,但是在测试时sentinel一直无法找到实例名称,看一下我的配置。
port 26379 # 哨兵sentinel的工作目录 dir "/tmp" sentinel deny-scripts-reconfig yes sentinel monitor mymaster redis-sentinel-0.redis-sentinel 6379 2 sentinel auth-pass mymaster wulaoer.org sentinel down-after-milliseconds mymaster 5000 sentinel failover-timeout mymaster 15000 sentinel parallel-syncs mymaster 2 sentinel config-epoch mymaster 3 sentinel leader-epoch mymaster 3
这里sentinel启动后会一直找到redis-sentinel-0.redis-sentinel
但是会提示:
*** FATAL CONFIG FILE ERROR (Redis 7.0.4) *** Reading the configuration file, at line 4 >>> 'sentinel monitor mymaster redis-sentinel-0.redis-sentinel 6379 2' Can't resolve instance hostname.
网络是通的,也没有什么限制,端口也没问题,但是这个使用容器名称解析不过去,看了一下redis的介绍,这里必须是要ip地址才可以,换成ip地址后,但是容器的ip地址会来回变化的,后来看到,可以在配置文件里加入sentinel resolve-hostnames yes
即可,这启动之后会把配置文件中的redis-sentinel-0.redis-sentinel
换成ip地址,如果redis-sentinel-0.redis-sentinel
的地址有变化,也会重新改变。
port 26379 # 哨兵sentinel的工作目录 dir "/tmp" sentinel deny-scripts-reconfig yes sentinel monitor mymaster redis-sentinel-0.redis-sentinel 6379 2 sentinel auth-pass mymaster wulaoer.org sentinel down-after-milliseconds mymaster 5000 sentinel failover-timeout mymaster 15000 sentinel parallel-syncs mymaster 2 sentinel config-epoch mymaster 3 sentinel leader-epoch mymaster 3 sentinel resolve-hostnames yes
然后随便测试就不会有问题的,也不会出现解析找不到主机名的问题。
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏