原创 2018年04月16日 15:43:54

1)基本条件:haproxy > v1.6 版本(测试时候觉得1.8版本更稳定)




      –  dns的返回值不正确,原因是backend的域名填写的有问题


如desktop-server  需转换为 desktop-server.flexhcs.rancher.internal

系统中是根据/etc/resol.conf 来自动添加的,但haproxy这边是直接向dns-server发送desktop-server这个域名的query,所以backend必须预先转换好


resolvers dns1
    nameserver internal-dns
    resolve_retries 3
    timeout resolve 10s
    timeout retry 10s
    hold other 30s
    hold refused 30s
    hold nx 30s
    hold timeout 30s
    hold valid 10s
    hold obsolete 30s

listen desktop_server_443
    mode tcp
    balance source
    timeout client 28801s
    timeout server 28801s
    server Desktop-Host desktop-server.flexhcs.rancher.internal:443 check resolvers dns1







5.3. Server IP address resolution using DNS
HAProxy allows using a host name on the server line to retrieve its IP address using name servers. By default, HAProxy resolves the name when parsing the configuration file, at startup and cache the result for the process' life. This is not sufficient in some cases, such as in Amazon where a server's IP can change after a reboot or an ELB Virtual IP can change based on current workload. This chapter describes how HAProxy can be configured to process server's name resolution at run time. Whether run time server name resolution has been enable or not, HAProxy will carry on doing the first resolution when parsing the configuration.
5.3.1. Global overview
As we've seen in introduction, name resolution in HAProxy occurs at two different steps of the process life:
1. when starting up, HAProxy parses the server line definition and matches a host name. It uses libc functions to get the host name resolved. This resolution relies on /etc/resolv.conf file.
2. at run time, HAProxy performs periodically name resolutions for servers requiring DNS resolutions.
A few other events can trigger a name resolution at run time:
- when a server's health check ends up in a connection timeout: this may be because the server has a new IP address. So we need to trigger a name resolution to know this new IP.
When using resolvers, the server name can either be a hostname, or a SRV label. HAProxy considers anything that starts with an underscore as a SRV label. If a SRV label is specified, then the corresponding SRV records will be retrieved from the DNS server, and the provided hostnames will be used. The SRV label will be checked periodically, and if any server are added or removed, haproxy will automatically do the same.
A few things important to notice:
- all the name servers are queried in the mean time. HAProxy will process the first valid response.
- a resolution is considered as invalid (NX, timeout, refused), when all the servers return an error.
5.3.2. The resolvers section
This section is dedicated to host information related to name resolution in HAProxy. There can be as many as resolvers section as needed. Each section can contain many name servers.
When multiple name servers are configured in a resolvers section, then HAProxy uses the first valid response. In case of invalid responses, only the last one is treated. Purpose is to give the chance to a slow server to deliver a valid answer after a fast faulty or outdated server.
When each server returns a different error type, then only the last error is used by HAProxy. The following processing is applied on this error:
1. HAProxy retries the same DNS query with a new query type. The A queries are switch to AAAA or the opposite. SRV queries are not concerned here. Timeout errors are also excluded.
2. When the fallback on the query type was done (or not applicable), HAProxy retries the original DNS query, with the preferred query type.
3. HAProxy retries previous steps <resolve_retires> times. If no valid response is received after that, it stops the DNS resolution and reports the error.
For example, with 2 name servers configured in a resolvers section, the following scenarios are possible:
- First response is valid and is applied directly, second response is ignored
- First response is invalid and second one is valid, then second response is applied
- First response is a NX domain and second one a truncated response, then HAProxy retries the query with a new type
- First response is a NX domain and second one is a timeout, then HAProxy retries the query with a new type
- Query timed out for both name servers, then HAProxy retries it with the same query type
As a DNS server may not answer all the IPs in one DNS request, haproxy keeps a cache of previous answers, an answer will be considered obsolete after <hold obsolete> seconds without the IP returned.
resolvers <resolvers id> Creates a new name server list labeled <resolvers id>
A resolvers section accept the following parameters:
accepted_payload_size <nb> Defines the maximum payload size accepted by HAProxy and announced to all the name servers configured in this resolvers section.
<nb> is in bytes. If not set, HAProxy announces 512. (minimal value defined by RFC 6891)
Note: to get bigger responses but still be sure that responses won't be dropped on the wire, one can choose a value between 1280 and 1410.
Note: the maximum allowed value is 8192.
nameserver <id> <ip>:<port> DNS server description: <id> : label of the server, should be unique
<ip> : IP address of the server
<port> : port where the DNS service actually runs
hold <status> <period> Defines <period> during which the last name resolution should be kept based on last resolution <status> <status> : last name resolution status. Acceptable values are "nx", "other", "refused", "timeout", "valid", "obsolete". <period> : interval between two successive name resolution when the last answer was in <status>. It follows the HAProxy time format.
<period> is in milliseconds by default.
Default value is 10s for "valid", 0s for "obsolete" and 30s for others.
resolution_pool_size <nb> (deprecated) Defines the number of resolutions available in the pool for this resolvers. If not defines, it defaults to 64. If your configuration requires more than <nb>, then HAProxy will return an error when parsing the configuration.
resolve_retries <nb> Defines the number <nb> of queries to send to resolve a server name before giving up.
Default value: 3
A retry occurs on name server timeout or when the full sequence of DNS query type failover is over and we need to start up from the default ANY query type.
timeout <event> <time> Defines timeouts related to name resolution <event> : the event on which the <time> timeout period applies to. events available are:
- resolve : default time to trigger name resolutions when no other time applied. Default value: 1s
- retry : time between two DNS queries, when no valid response have been received. Default value: 1s <time> : time related to the event. It follows the HAProxy time format. <time> is expressed in milliseconds.
resolvers mydns nameserver dns1
nameserver dns2
resolve_retries 3
timeout resolve 1s
timeout retry 1s
hold other 30s
hold refused 30s
hold nx 30s
hold timeout 30s
hold valid 10s
hold obsolete 30s


  • 1970年01月01日 08:00

haproxy frontend 和backend

frontend 接收请求的前端虚拟节点,Frontend可以根据规则直接指定具体使用后端的 backend(可动态选择)。 backend 后端服务集群的配置,是真实的服务器,一个Backend...
  • zhaoyangjian724
  • zhaoyangjian724
  • 2015-07-07 19:43:27
  • 5715

haproxy 多域名 多证书绑定

bind *:80 bind *:443 ssl crt /etc/haproxy/keys/pod100.com.pem crt /etc/haproxy/ke...
  • zhaoyangjian724
  • zhaoyangjian724
  • 2016-12-19 22:22:29
  • 1602

haproxy 页面重定向(域名跳转)

redirect location [code ] [{if | unless} ] redirect prefix [code ] [{if | unless} ] 重定向,相当于rew...
  • zhaoyangjian724
  • zhaoyangjian724
  • 2015-07-07 17:31:39
  • 5730


global log local0 info #[err warning info debug] //日志位置 maxconn 4096 ...
  • youyudehexie
  • youyudehexie
  • 2012-05-27 14:04:55
  • 8479

Haproxy frontend listen分析

Haproxy的frontend到底是怎么进行listen,怎么accept客户端发来的请求呢?这边就按照haproxy 1.4.19进行分析一下。要知道frontend进行了哪些端口的侦听及其相关配...
  • chen_jianjian
  • chen_jianjian
  • 2015-01-23 14:55:19
  • 2522

解决Haproxy误报"backend xxx_server has no server available!"

把Haproxy用在生产环境后,经常会遇到Haproxy误报"backend xxx_server has no server available!"的消息,而实际上,xxx_server是正常运行的...
  • skykingf
  • skykingf
  • 2015-04-08 16:55:17
  • 5148

No backend servers available

No backend servers available 如何解决?
  • wanlixingzhe
  • wanlixingzhe
  • 2012-03-27 09:54:45
  • 2736

多个haproxy 之间跳转

C:\>ping wechatTest.winfae.com 正在 Ping wechatTest.winfae.com [] 具有 32 字节的数据: 来自 120.55....
  • zhaoyangjian724
  • zhaoyangjian724
  • 2016-06-29 16:40:53
  • 1476

haproxy 关于域名重定向

1.首先 每个域名都要有属于自己的 ip www.a.com www.b.com www.c.com    1...
  • lyj1101066558
  • lyj1101066558
  • 2016-03-17 20:23:34
  • 1527