如何为 haproxy 配置 Amazon ELB ping 目标

如何为 haproxy 配置 Amazon ELB ping 目标

我正在尝试设置 Amazon ELB 以将请求路由到几个 haproxy 服务器。ELB 需要对各个服务器进行 ping 目标以进行健康检查。它在端口 80 处使用 index.html。我正在努力在 haproxy 中配置 index.html。这是我的 haproxy 配置:


global
    log         127.0.0.1 local2
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

defaults
    mode        http
    option      dontlognull
    option      httpclose
    option      httplog
    option      forwardfor
    option      redispatch
    option httpchk HEAD /index.html HTTP/1.0
    timeout connect 10000 # default 10 second time out if a backend is not found
    timeout client 300000
    timeout server 300000
    maxconn     60000
    retries     3

#
# Host HA-Proxy's web stats on Port 81.
listen stats :1936
    mode http
    stats enable
    stats hide-version
    stats realm Haproxy\ Statistics
    stats uri /
    stats auth Username:Password

frontend  main *:80
    log 127.0.0.1 local2
    capture request  header         X-Forwarded-For      len 500
    capture response header         X-Query-Result       len 100
    acl url_webapp                  path_beg -i /supporttoolbar
    acl url_jsonproxy               path_beg -i /proxy

backend webapp
    balance     roundrobin
    server      webapp1 10.100.86.xxx:80 check
backend jsonproxy
    balance     roundrobin
    server      webapp1 10.100.86.xxx:80 check

html 页面位于/var/www/html/

我尝试添加选项 httpchk HEAD /index.html HTTP/1.0在下面默认值部分,但没有作用。

任何指点都将受到赞赏。

谢谢

答案1

请看一下这个要旨。它基本上描述/配置了您所需要的内容:

# Create a monitorable URI which returns a 200 if at least 1 server is up.
# This could be used by Traverse/Nagios to detect if a whole server set is down.
acl servers_down nbsrv(servers) lt 1
monitor-uri /haproxy?monitor
monitor fail if

答案2

我通过在 Haproxy 配置文件中添加以下条目找到了替代方案。


defaults
    mode        http
    option      dontlognull
    option      httpclose
    option      httplog
    option      forwardfor
    option      redispatch
    timeout connect 10000 # default 10 second time out if a backend is not found
    timeout client 300000
    timeout server 300000
    monitor-uri /index.html
    maxconn     60000
    retries     3

入口监控-uri/index.html条目成功了。Haproxy 有内置的健康检查,如果服务正常,则返回 200。我只是模拟它以使用 Amazon ELB 识别的 /index.html。

相关内容