2014-03-19 32 views
6

假设我有一个在localhost:9000上运行的tcp服务器和一个在localhost:8000上运行的HTTP服务器。 HTTP服务器公开一个URL“/ healthz”,如果tcp服务器健康则返回200,如果tcp服务器不健康则返回500。也就是执行:在HA代理中为TCP服务器使用HTTP健康检查

curl localhost:9000/healthz 

将根据tcp服务器的运行状况返回状态200或状态500。

我希望HAProxy使用localhost:8000/healthz作为tcp服务器的健康检查。那可能吗?

回答

3

回答此问题,以防有人来这里寻找答案。

我原以为这不起作用,因为你混合了HTTP和TCP,但它似乎是可能的。我刚刚测试过v1.4.24。诀窍是指定一个不同的端口来检查后端的服务器行。这是一个适用于我的配置程序片段。

 
frontend httpfrontend 
    bind *:8080 
    mode http 
    option httplog 
    default_backend http-backend 

backend http-backend 
    balance roundrobin 
    mode http 
    option httplog 
    option httpclose 
    reqadd X-Forwarded-Proto:\ http 
    server server1 localhost:8000 

frontend tcpfrontend 
    bind *:1080 
    mode tcp 
    option tcplog 
    default_backend tcp-backend 

backend tcp-backend 
    mode tcp 
    option tcplog 
    # specify the format of the health check to run on the backend 
    option httpchk GET /healthz HTTP/1.0\r\nUser-agent:\ LB-Check\ TCP 
    # check -> turn on checks for this server 
    # port 8000 -> send the checks to port 8000 on the backend server (rather than 9000) 
    # inter 60000 -> check every 60s 
    server server1 localhost:9000 check port 8000 inter 60000 
2

这对我的作品在1.4.24版本(与@chrskly),没有任何技巧:

listen service 0.0.0.0:80 
    mode tcp 
    balance roundrobin 

    option tcplog 

    option httpchk GET http://service.com/healthcheck 

    server server1.service.com 192.168.0.101:80 check inter 2000 
    server server2.service.com 192.168.0.102:80 check inter 2000