
云原生
Docker Swarm 中 Nginx 反代网关报 "No route to host" 的根因与解法
背景 集群使用 Docker Swarm 部署,Nginx 通过反向代理访问网关服务 wulaoer。按 Swarm 规则,Nginx 配置里写服务名加端口即可通信,例如: 但实际
在部署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
然后随便测试就不会有问题的,也不会出现解析找不到主机名的问题。
评论 0