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

haproxy: how to prepare a server maintenance without kicking app sessions?

· 52CE 我爱测

The issue I'm using haproxy to load balance web servers. I use session persistence with additional cookies as some applications use session files and these are not synchronized between servers. I want to disable a server for main…

问题原文

原帖链接 · Christophe Drevet · CC BY-SA 3.0

The issue

I'm using haproxy to load balance web servers. I use session persistence with additional cookies as some applications use session files and these are not synchronized between servers.

I want to disable a server for maintenance, but without breaking sessions. So I would like to allow existing clients to continue their application session, but not accept new clients.

haproxy behavior

  • I set a server to "going to maintenance"
  • if a client has the cookie set, use the server even if marked as "going into maintenance"
  • if a new client (without cookie) come, it is directed to another server
  • after all clients end their application sessions, no more client would have the cookie set to this particular server, and I'd be good to shut it down without user disruption.

Do you think this is achievable with some haproxy configuration? Or is there a clever way to do it?

Other ways

Non exhaustive list of other ways to achieve this need:

  • synchronize session files between servers (needs a way to synchronize files between several servers, or a common single mountpoint)
  • use database to store session information (needs to change application behavior)

More details

I use this kind of configuration:

frontend https-in
   bind xxx.xxx.xxx.xxx:443 ssl crt /etc/haproxy/ssl/_default.pem crt /etc/haproxy/ssl
   reqadd X-Forwarded-Proto:\ https

   acl APP1 hdr(host) -i APP1.atac.local
   use_backend APP1 if APP1

   default_backend _default

backend APP1
   redirect scheme https if !{ ssl_fc }
   mode http
   balance roundrobin
   cookie HAPROXY_SESSION insert indirect
   option httpchk HEAD /haproxy_test_page.php HTTP/1.0\nUser-Agent:\ HAProxy
   server SRV1 SRV1_IP:PORT cookie SRV1 check
   server SRV2 SRV2_IP:PORT cookie SRV2 check

If I just disable SRV1 (with haproxy cli command), I think all application sessions opened on SRV1 will break after the end of the current HTTP "session". Is that right?

已采纳解答

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

Put the server in drain mode using the web management interface. That provides the exact functionality you're looking for.

For details on the web management interface - https://github.com/Aidaho12/haproxy-wi

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

资料来源与适用范围

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

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

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