大网数据广告活动
服务器运维问答

Make HAProxy re-relay a request to a failed server

· 52CE 我爱测

I was wondering if there is a way with HAProxy to re-send a failed request to another server if the original server is down. We run a REST API on multiple servers behind multiple HAProxy instances. There is no balance affinity, b…

问题原文

原帖链接 · Tigraine · CC BY-SA 3.0

I was wondering if there is a way with HAProxy to re-send a failed request to another server if the original server is down.

We run a REST API on multiple servers behind multiple HAProxy instances.

There is no balance affinity, balance is done purely on round-robin.

To upgrade one server we can just restart it and due to health checks HAProxy will usually not send any data to this server.

BUT: If the server goes down between two health checks and HAProxy forwards a HTTP request to that server without knowing yet that it's down - that request fails (obviously).

Is there a way to configure HAProxy in such a way that it will notice that the connection went down and retry on another server?

Or at least make HAProxy mark that server as unhealthy directly so we only loose one request and not multiple ones during the transition.

HAProxy is running inside a docker container and the servers are also docker containers.

已采纳解答

原帖链接 · seven · CC BY-SA 4.0

Yes in version 2.0 haproxy has implemented layer 7 retries.

The new retry-on configuration directive defines in which case to retry failed HTTP request to another server. Earlier versions had option redispatch and retries but would only redispatch in case of connection problems (not eg. errors/timeouts after connection has been established).

Be careful not to retry POST so you don't end up with multiple duplicate database submissions in case of eg. slow backends.

Example:

backend test
    balance roundrobin
    option redispatch 1
    retry-on all-retryable-errors
    retries 3
    http-request disable-l7-retry if METH_POST

    server app1 192.168.0.1:80 maxconn 30 check
    server app2 192.168.0.2:80 maxconn 30 check
    server app3 192.168.0.3:80 maxconn 30 check

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-10-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。