大网数据广告活动
服务器运维问答

Hostnames in HAProxy configuration file

· 52CE 我爱测

My haproxy.cfg file has two backend servers using hostnames: server ops-ca-revealv2e-prod-1 ops-ca-revealv2e-prod-1:443 cookie ops-ca-revealv2e-prod-1 ssl weight 1 maxconn 512 check server ops-ca-revealv2e-prod-2 ops-ca-revealv2e…

问题原文

原帖链接 · Naijaba · CC BY-SA 3.0

My haproxy.cfg file has two backend servers using hostnames:

server ops-ca-revealv2e-prod-1 ops-ca-revealv2e-prod-1:443 cookie ops-ca-revealv2e-prod-1 ssl weight 1 maxconn 512 check

server ops-ca-revealv2e-prod-2 ops-ca-revealv2e-prod-2:443 cookie ops-ca-revealv2e-prod-2 ssl weight 1 maxconn 512 check

These hostnames are part of Amazon OpsWorks and are injected into /etc/hosts automatically whenever an instance comes up or down. If I attempt to restart HAProxy when one of the instances is down, I receive the error:

[ALERT] 362/225440 (27202) : parsing [/opt/haproxy-ssl/haproxy.cfg:42] : 'server ops-ca-revealv2e-prod-2' : invalid address: 'ops-ca-revealv2e-prod-2' in 'ops-ca-revealv2e-prod-2:443'
[ALERT] 362/225440 (27202) : Error(s) found in configuration file : /opt/haproxy-ssl/haproxy.cfg
[ALERT] 362/225440 (27202) : Fatal errors found in configuration.

Is there a way to tell HAProxy to check if a hostname is valid? If it is valid, use it, if not, ignore it.

已采纳解答

原帖链接 · Bharat · CC BY-SA 3.0

In haproxy >= 1.7, you should be able to use the init-addr option, specifying none to prevent DNS resolution at startup.

From the docs:

init-addr {last | libc | none | <ip>},[...]*

Indicate in what order the server's address should be resolved upon startup if it uses an FQDN. Attempts are made to resolve the address by applying in turn each of the methods mentionned in the comma-delimited list. The first method which succeeds is used. If the end of the list is reached without finding a working method, an error is thrown. Method "last" suggests to pick the address which appears in the state file (see "server-state-file"). Method "libc" uses the libc's internal resolver (gethostbyname() or getaddrinfo() depending on the operating system and build options). Method "none" specifically indicates that the server should start without any valid IP address in a down state. It can be useful to ignore some DNS issues upon startup, waiting for the situation to get fixed later. Finally, an IP address (IPv4 or IPv6) may be provided.

So your config line could be:

server s1 myhostname init-addr none

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-12-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。