Haproxy 1.6.2 无法识别解析器部分

Haproxy 1.6.2 not recognizing resolvers section

作为测试,我有一个本地绑定实例 运行:

>netstat -ant | grep LISTEN
tcp        0      0 10.72.186.23:53         0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN
...

>nslookup mysubdomain.example.com 127.0.0.1
Server:     127.0.0.1
Address:    127.0.0.1#53

Name:   mysubdomain.example.com
Address: nn.nn.nn.251
Name:   mysubdomain.example.com
Address: nn.nn.nn.249
Name:   mysubdomain.example.com
Address: nn.nn.nn.201
Name:   mysubdomain.example.com
Address: nn.nn.nn.138

我在同一台主机上 运行 haproxy 1.6.2,带有解析器部分:

resolvers dns
    nameserver dns1 127.0.0.1:53
    nameserver dns2 10.72.186.23:53
    hold valid 10s

它没有拒绝解析器部分,但似乎也没有使用它。它没有显示在统计页面中,并尝试添加此服务命令:

server mysubdomain-dev mysubdomain.example.com

导致此错误:

>service haproxy restart
 * Restarting haproxy haproxy
[ALERT] 322/171813 (10166) : parsing [/etc/haproxy/haproxy.cfg:77] : 'server mysubdomain-dev' : invalid address: 'mysubdomain.example.com' in 'mysubdomain.example.com'
[ALERT] 322/165300 (29751) : Error(s) found in configuration file : /etc/haproxy/haproxy.cfg
[ALERT] 322/165300 (29751) : Fatal errors found in configuration.

haproxy 文档 https://cbonte.github.io/haproxy-dconv/configuration-1.6.html 表明这应该有效。

服务器 <名称> <地址>[:[端口]] [参数*]

...

是服务器的 IPv4 或 IPv6 地址。或者,一个 支持可解析的主机名,但该名称将被解析 在启动期间。地址“0.0.0.0”或“*”有特殊含义。

是否有其他部分需要添加到激活解析器部分的 haproxy.cfg?

当 HAProxy 首次启动时,它会尝试解析所有后端中任何服务器的主机名以填充服务器结构。在第一个启动阶段,HAProxy 使用 OS 解析器,即通常在 /etc/resolv.conf 文件中定义的服务器。

只有稍后,当服务器的 IP 地址在检查期间更新时,HAProxy 才会使用其内部解析器配置和内部 DNS 解析器。

从您的错误描述来看,您的主机本身似乎无法解析 mysubdomain.example.com 主机名。只有当 HAProxy 可以在没有显式命名的名称服务器的情况下解析主机名时,它才能启动。这可以用例如

来验证
dig mysubdomain.example.com

可能是您没有指定用于该服务器的解析器

服务器 mysubdomain-dev mysubdomain.example.com ->

服务器 mysubdomain-dev mysubdomain.example.com 解析器 dns