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

Preserve backend server status when reloading haproxy

· 52CE 我爱测

Because I have a large pool of https certificates that changes from day to day (massive multitenant application with many domains), I have a script that may reload haproxy at nearly random times. This works fine. I also set backe…

问题原文

原帖链接 · Ross Presser · CC BY-SA 3.0

Because I have a large pool of https certificates that changes from day to day (massive multitenant application with many domains), I have a script that may reload haproxy at nearly random times. This works fine.

I also set backend servers to MAINT when I am deploying new versions of applications to them. This also works fine.

The trouble is that if the reload happens, any servers that I had set to MAINT status are instead reloaded as READY. This lets customers see waits or even error messages.

Is there a way to preserve the current status of backend servers when reloading haproxy?

已采纳解答

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

Not sure which version you're using, the following needs HAProxy >= 1.6~:

You might want to have a look at the load-server-state-from-file directive, which allows

seamless reloads of HAProxy.

This directive points HAProxy to a file where server state from previous running process has been saved. That way, when starting up, before handling traffic, the new process can apply old states to servers exactly has if no reload occured. [...]

(That's just an excerpt, for more details follow the link.)

Using this, your config could look like (only relevant parts shown):

global
  server-state-file /var/lib/haproxy/server-state
  stats socket /var/lib/haproxy/stats

defaults
  load-server-state-from-file global

Your reload command could then look like the following:

socat /var/lib/haproxy/stats - <<< \"show servers state\" > /var/lib/haproxy/server-state && systemctl reload-or-restart haproxy

That is:

  • Connect to the stats socket via socat, get the states of the servers and / or backends and write to the state file.
  • After this, if all went well, reload or restart HAProxy.

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

资料来源与适用范围

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

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

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