2016-09-29 109 views
0

当遇到特定的http-状态代码时,是否可以进行HaProxy故障转移?基于http状态的HaProxy故障转移

如果tomcat服务器本身停止/失败,我有以下通用haproxy代码可以正常工作。然而,当http状态代码502坏网关500内部服务器错误也可以从tomcat遇到时,我想故障切换。即使在任何节点中遇到500,404状态码,以下配置仍会继续发送流量。

backend db01_replication 
    mode http 
    bind 192.168.0.1:80 
    server app1 10.0.0.19:8080 check inter 10s rise 2 fall 2 
    server app2 10.0.0.11:8080 check inter 10s rise 2 fall 2 
    server app3 10.0.0.13:8080 check inter 10s rise 2 fall 2 

在此先感谢

回答

1

我发现下面的HAProxy的HTTP检查预期解析负载平衡基于HTTP状态代码。

# Only accept status 200 as valid 
http-check expect status 200 

# Consider SQL errors as errors 
http-check expect ! string SQL\ Error 

# Consider all http status 5xx as errors 
http-check expect ! rstatus ^5 

为了故障切换时遇到一个500错误时,可以HAProxy的配置看起来像:

backend App1_replication 
mode http 
bind 192.168.0.1:80 
http-check expect ! rstatus ^5 
server app1 10.0.0.19:8080 check inter 10s rise 2 fall 2 
server app2 10.0.0.11:8080 check inter 10s rise 2 fall 2 
server app3 10.0.0.13:8080 check inter 10s rise 2 fall 2 

来源 https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#http-check%20expect