HAProxy 健康检查

12

我的当前设置有2个配置了keepalived高可用性的HAProxy,这两个代理充当虚拟网络服务的反向代理和负载均衡器。我知道HAProxy可以检查其后端的健康状况(我已经配置了),但我的问题是另外一件事。

在我们公司,有一个F5 Big-IP负载均衡器作为第一道防线,需要时它会将请求重定向到我的HAProxies。

我需要知道是否有一种让我的F5 Big-IP检查HAProxies前端健康状况的方法,这样当代理启动时就不会丢失任何请求。

谢谢

3个回答

15

4

以下内容来自HAProxy参考手册

Health-checking mode
--------------------
This mode provides a way for external components to check the proxy's health.
It is meant to be used with intelligent load-balancers which can use send/expect
scripts to check for all of their servers' availability. This one simply accepts
the connection, returns the word 'OK' and closes it. If the 'option httpchk' is
set, then the reply will be 'HTTP/1.0 200 OK' with no data, so that it can be
tested from a tool which supports HTTP health-checks. To enable it, simply
specify 'health' as the working mode :

Example :
---------
    # simple response : 'OK'
    listen health_check 0.0.0.0:60000
        mode health

    # HTTP response : 'HTTP/1.0 200 OK'
    listen http_health_check 0.0.0.0:60001
        mode health
        option httpchk

在较新的haproxy版本中,此模式已被弃用,不应再使用,因为可以通过将TCP或HTTP模式与“monitor”关键字相结合来实现相同甚至更好的效果。http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#monitor - nelaaro
有没有使用较新的“monitor”关键字样式和TCP监听器的示例 - 在文档中似乎不明显(检查版本2.6)。 - tuck1s

1
从HAProxy文档中。
Example:
frontend www
    mode http
    acl site_dead nbsrv(dynamic) lt 2
    acl site_dead nbsrv(static)  lt 2
    monitor-uri   /site_alive
    monitor fail  if site_dead

查看参考文档。

http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4.2-monitor-uri

<uri>     is the exact URI which we want to intercept to return HAProxy's
          health status instead of forwarding the request.

When an HTTP request referencing <uri> will be received on a frontend,
HAProxy will not forward it nor log it, but instead will return either
"HTTP/1.0 200 OK" or "HTTP/1.0 503 Service unavailable", depending on failure
conditions defined with "monitor fail". This is normally enough for any
front-end HTTP probe to detect that the service is UP and running without
forwarding the request to a backend server. Note that the HTTP method, the
version and all headers are ignored, but the request must at least be valid
at the HTTP level. This keyword may only be used with an HTTP-mode frontend.

Monitor requests are processed very early. It is not possible to block nor
divert them using ACLs. They cannot be logged either, and it is the intended
purpose. They are only used to report HAProxy's health to an upper component,
nothing more. However, it is possible to add any number of conditions using
"monitor fail" and ACLs so that the result can be adjusted to whatever check
can be imagined (most often the number of available servers in a backend).

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接