【问题标题】:HaProxy failover based on http statusHaProxy 基于 http 状态的故障转移
【发布时间】:2017-04-19 20:22:39
【问题描述】:

HaProxy 在遇到特定的 http-status 代码时是否可以进行故障转移?

如果 tomcat 服务器本身停止/失败,我有以下通用 haproxy 代码可以正常工作。但是,当从 tomcat 也遇到 http-status 代码 502 Bad Gateway500 Internal Server Error 时,我想进行故障转移。以下配置即使在任意节点遇到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

提前致谢

【问题讨论】:

    标签: load-balancing haproxy


    【解决方案1】:

    我发现以下 HaProxy http-check expect 可以根据 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-12
      • 1970-01-01
      • 2013-06-01
      • 2012-02-11
      • 2021-08-21
      • 1970-01-01
      • 1970-01-01
      • 2012-03-05
      相关资源
      最近更新 更多