如果DNS解析失败,haproxy将暂停运行状况检查

时间:2017-07-17 21:06:33

标签: mqtt haproxy

我们正在使用haproxy根据可用性(优先于本地服务器)在本地MQTT代理和云代理之间切换。 haproxy.cfg看起来像这样:

global
  log 127.0.0.1   local1
  maxconn 1000
  daemon
  debug
  #quiet
  tune.bufsize 1024576
  stats socket /var/run/haproxy.sock mode 600 level admin

defaults
  log     global
  mode    tcp
  option  tcplog
  retries 3
  option redispatch

  timeout connect 5000
  timeout client 50000
  timeout server 50000

# Listen to all MQTT requests (port 1883)
listen mqtt
  bind *:1883

  mode tcp

  balance first  # Connect to first available

  timeout client  3h
  timeout server  3h
  option clitcpka
  option srvtcpka


  # MQTT server 1 - local wifi
  server wifi_broker localserver.local:1883 init-addr libc,last,none check inter 3s rise 5 fall 2 maxconn 1000 on-marked-up shutdown-backup-sessions on-marked-down shutdown-sessions

  # MQTT server 2 - cloud
  server aws_iot xxxxx.amazonaws.com:8883 backup check backup ssl verify none ca-file ./root-CA.crt crt ./cert.pem inter 5s rise 3 fall 2

listen stats
  bind :9000
  mode http
  stats enable  # Enable stats page
  stats hide-version  # Hide HAProxy version
  stats realm Haproxy\ Statistics  # Title text for popup window
  stats uri /haproxy_stats  # Stats URI

如果本地代理在haproxy启动时可用,则一切正常。但是,如果在haproxy启动时与本地计算机的wifi连接关闭,init-addr none仍然允许它开始使用备份服务器(aws_iot)。本地服务器标记为" Down for Maintenance"并且不再执行健康检查。即使在网络启动并运行后,haproxy也不知道它,也不会从云服务器切换回来。

有没有办法让它认为未解析的域名与普通域名相同" down"条件?

我现在看到的一个替代方案是让脚本在后台轮询域名并发送"启用服务器"命令到haproxy控件套接字一旦启动。对于一些非常简单的东西来说,这似乎过于迂回!

更新: 在本地连接启动并运行后,运行命令echo "enable server mqtt/wifi_server" | socat /var/run/haproxy.sock stdio不会切换后端。 haproxy永远不会切换回本地服务器,只需重新启动它。

更新2: 已将init-addr none更改为init-addr libc,last,none

1 个答案:

答案 0 :(得分:0)

您正在使用" init-addr none "因此,当服务器处于关闭状态时,服务器将在没有任何有效IP地址的情况下启动。此外,您当前的配置使HAProxy能够在启动时解析主机名 ,如here所述。
因此,要使HAProxy在启动后解析 localserver.local 以获取IP并发送运行状况检查,您需要在HAProxy中配置resolvers section