【问题标题】:can haproxy ensure every call to backend server is successful when one of backend server is down?当后端服务器之一关闭时,haproxy 能否确保对后端服务器的每次调用都成功?
【发布时间】:2020-08-28 20:24:21
【问题描述】:

haproxy 配置。


defaults
  option forwardfor
  log global
  option httplog
  log 127.0.0.1 local3
  option  dontlognull
  retries 3
  option redispatch
  timeout connect 5000ms
  timeout client  5000ms
  timeout server 5000ms

listen stats
    bind    *:9000
    mode    http
..............................................
backend testhosts
    mode http
    balance roundrobin
    option httpchk HEAD /sabrix/scripts/menu-common.js
    server host1 11.11.11.11:9080  check inter 2000 rise 1 fall 2
    server host2 11.11.11.12:9080  check inter 2000 rise 1 fall 2

如果11.11.11.11的服务宕机,haproxy会在2-3秒左右得到503和404错误(取决于inter值,如果inter值非常小,404错误的数量会减少)。

2020-08-25T11:58:14 11.11.11.11:9080 200 POST /tsturl1 HTTP/1.1 2274
2020-08-25T11:58:14 11.11.11.22:9080 200 POST /tsturl1 HTTP/1.1 448
2020-08-25T11:58:14 11.11.11.11:9080 503 POST /tsturl1 HTTP/1.1 0
2020-08-25T11:58:14 11.11.11.11:9080 404 POST /tsturl1 HTTP/1.1 0
2020-08-25T11:58:14 11.11.11.11:9080 200 POST /tsturl1 HTTP/1.1 1503
2020-08-25T11:58:16 11.11.11.22:9080 200 POST /tsturl1 HTTP/1.1 617
2020-08-25T11:58:16 11.11.11.11:9080 404 POST /tsturl1 HTTP/1.1 0
2020-08-25T11:58:16 11.11.11.22:9080 200 POST /tsturl1 HTTP/1.1 618
2020-08-25T11:58:16 11.11.11.11:9080 404 POST /tsturl1 HTTP/1.1 0
2020-08-25T11:58:16 host1 is DOWN, reason: Layer7 wrong status, code: 404, info: "Not Found", check duration: 0ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue. 2020-08-25T11:58:16 11.11.11.22:9080 200 POST /tsturl1 HTTP/1.1 645
2020-08-25T11:58:16 11.11.11.22:9080 200 POST /tsturl1 HTTP/1.1 618\

我的问题是:为什么参数重试不起作用?当后端服务器之一关闭时,haproxy 能否确保对后端服务器的每次调用都成功? Haproxy 1.5.18 的版本。我也试过 2.2.2,我得到了同样的错误。

【问题讨论】:

  • 我尝试在 haproxy.cfg 中添加“http-check disable-on-404”,然后重新启动 haproxy,但它似乎不起作用。 ''' 2020-08-28T16:58:14 11.11.11.11:9080 200 POST /tsturl1 HTTP/1.1 2274 2020-08-28T16:58:14 11.11.11.22:9080 200 POST /tsturl1 HTTP/1.1 448 2020-08 -28T16:58:14 11.11.11.11:9080 503 POST /tsturl1 HTTP/1.1 0

标签: backend haproxy


【解决方案1】:

您已经在单独的thread 中提出了这个问题,我为您提供了可以回答您问题的资源。您似乎没有阅读我提供的资源,也没有因回答您的问题而给我加分。

如前所述,您需要使用 HAProxy 2.0 及以上版本。但是,如果您阅读了我提供的博客文章,您会发现您还需要使用 retry-on

【讨论】:

  • 非常感谢,我刚刚尝试将“重试”设置为无(也将重试次数设置为 3),我在测试期间只能在错误中获得 3 条错误记录(每秒大约 10 个请求为我的测试)。我的问题是:haproxy 是否可以将失败的调用直接发送到另一个可用的后端服务器,以确保每个请求都能获得成功的响应,即使其中一个后端服务器已关闭?
  • 您可以使用option redispatch 将请求发送到后端的不同服务器
  • 请看我的配置,我确实在默认部分配置了“option redispatch”,但是我的日志文件中仍然有一些错误调用记录,我应该在后端配置“option redispatch”而不是默认配置部分?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-18
  • 2012-03-14
  • 2022-10-13
  • 2014-03-03
  • 1970-01-01
  • 2013-09-02
  • 2018-01-25
相关资源
最近更新 更多