2016-09-29 105 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