问题描述
我在hsproxy.cfg中为后端服务器使用dns名称,例如
后端s0服务器server0 server0.x.y.local:8080后端s1服务器server1 server1.x.y.local:8080
启动后,名称解析可以正常工作.但是,一旦后端服务器的IP地址更改,请求haproxy的请求就会花费很长时间(例如25秒),然后以503响应(原因:SC).它不会更新或重新解析dns名称.但是该计算机上的 curl
可以正常工作,因此操作系统会正确更新这些dns条目的ip地址.因此,看起来haproxy会在启动时缓存ip地址,而从不对其进行更改.
我正在使用haproxy作为kubernetes集群内部的Pod(不确定这是否重要).
从我在官方文档中所读的内容来看,libc选项应该使用操作系统的解决方法吗?我曾尝试将 init-addr libc
放进去,但这并没有帮助,haproxy仍然可以在机器上永久运行503并永久响应,而dns可以完美解析.
我还看到使用 resolver
条目时可能会进行一些微调,您可以在其中配置刷新时间等.在haproxy.cfg中不使用硬编码名称服务器而仅使用它们的情况下,是否可以进行微调?从操作系统?
除非您另行告知,否则HAProxy确实会缓存已解析的IP,这似乎是正确的.
您已经发现使用解析器和自定义检查间隔进行配置应该可以解决问题( resolvers dns check inter 1000
and hold valid
),但是您也可以正确的是,这也需要一个 resolvers
部分.从HAProxy 1.9开始,您可以使用 parse-resolv-conf
使用本地解析器:
解析器mydns解析解析配置持有有效的10秒后端站点平衡最小二乘服务器站点server.example.com:80个解析器mydns检查inter 1000
HAProxy文档可以帮助您进行进一步的配置: https://cbonte.github.io/haproxy-dconv/1.9/configuration.html#5.3.2-parse-resolv-conf
I'm using dns names for my backend servers in my hsproxy.cfg like
backend s0
server server0 server0.x.y.local:8080
backend s1
server server1 server1.x.y.local:8080
The name resolution works fine after startup. But as soon as the ipadress of a backendserver changes, requests to haproxy take a long time (like 25 seconds) and then respond with 503 (reason: SC). It doesn't update or reresolve the dns names. But a curl
on that machine works fine so the operating system updates the ip adress for those dns entries correctly. So it looks like haproxy is caching the ip adress on startup and never changes them.
I'm using haproxy as a pod inside of a kubernetes cluster (not sure if that matters).
From what I read in the offical docs, the libc option should use the operating systems resolve? I have tried putting init-addr libc
but it didn't help, haproxy still responds with long running 503 forever while on the machine, dns resolves perfectly.
I have also seen that there are some fine tunings possible when using a resolver
entry, where you can configure refresh times etc. Is this possible without hardcode nameservers in haproxy.cfg and just use the ones from the operating system?
Seems to be correct that HAProxy does cache the resolved IP unless you tell it otherwise.
As you already found the configuration using a resolver and a custom check interval should do the trick (resolvers dns check inter 1000
and hold valid
), but you are also right that this requires a resolvers
section as well. Since HAProxy 1.9 you can use parse-resolv-conf
to use the local resolver:
resolvers mydns
parse-resolv-conf
hold valid 10s
backend site-backend
balance leastconn
server site server.example.com:80 resolvers mydns check inter 1000
The HAProxy documentation can help you with further configuration: https://cbonte.github.io/haproxy-dconv/1.9/configuration.html#5.3.2-parse-resolv-conf
这篇关于HAProxy使用操作系统中的DNS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!