写在最前

目前遇到 HAProxy 运行一段时间后进程异常退出 的问题。经过排查,发现这是已知的老版本缺陷,有社区反馈遇到类似情况并建议通过升级解决。原环境使用的是 2.2.16,该版本已接近维护终止,不再提供修复支持,因此选择通过 源码编译升级到最新的 3.2 长期支持版本,以获得更稳定的运行表现和后续的安全更新。

https://github.com/haproxy/haproxy/issues/833

https://github.com/haproxy/haproxy/issues/3030

1. 操作流程

1.1 编译源码

https://github.com/haproxy/haproxy/releases/tag/v3.2.0

# 卸载旧版本
[root@hybxvdka01 haproxy-3.2.0]# rpm -qa | grep haproxy
haproxy-help-2.2.16-9.ky10.noarch
haproxy-2.2.16-9.ky10.aarch64

yum remove -y haproxy haproxy-help

# 安装依赖
yum install -y gcc make pcre-devel openssl-devel systemd-devel zlib-devel libtool lua-devel

# tar -xf 解压进入到源码目录
make TARGET=linux-glibc CPU=generic \
    USE_OPENSSL=1 \
    USE_PCRE=1 \
    USE_ZLIB=1 \
    USE_NS=1 \
    PREFIX=/usr

# 开始安装
make install PREFIX=/usr

# 查看版本
[root@hybxvdka01 haproxy-3.2.0]# haproxy -v
HAProxy version 3.2.0-e134140d282c 2025/05/28 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2030.
Known bugs: http://www.haproxy.org/bugs/bugs-3.2.0.html
Running on: Linux 4.19.90-52.48.v2207.ky10.aarch64 #4 SMP Tue Jun 3 12:56:10 CST 2025 aarch64

1.2 启动程序

如果系统里已经存在旧的 haproxy.cfg 配置文件,在升级或重新安装 HAProxy 时,它不会被直接覆盖,而是会被自动重命名为:/etc/haproxy/haproxy.cfg.rpmsave

这样做是为了避免配置被误删或覆盖。要继续使用原有配置,需要手动将它恢复为默认名称:mv /etc/haproxy/haproxy.cfg.rpmsave /etc/haproxy/haproxy.cfg 之后才能正常启动 HAProxy

systemctl daemon-reload systemctl enable --now haproxy

cat > /etc/systemd/system/haproxy.service <<'EOF'
[Unit]
Description=HAProxy Load Balancer
After=network.target

[Service]
Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/var/run/haproxy.pid"
ExecStart=/usr/sbin/haproxy -Ws -f $CONFIG -p $PIDFILE
ExecReload=/usr/sbin/haproxy -f $CONFIG -c -q
ExecReload=/bin/kill -USR2 $MAINPID
Restart=always
Type=notify

[Install]
WantedBy=multi-user.target
EOF

1.3 验证服务

● haproxy.service - HAProxy Load Balancer
   Loaded: loaded (/etc/systemd/system/haproxy.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2025-08-28 16:00:37 CST; 3min 15s ago
 Main PID: 1802225 (haproxy)
   Status: "Ready."
    Tasks: 17
   Memory: 15.9M
   CGroup: /system.slice/haproxy.service
           ├─1802225 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid
           └─1802227 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid

Aug 28 16:00:37 hybxvdka01 systemd[1]: Starting HAProxy Load Balancer...
Aug 28 16:00:37 hybxvdka01 haproxy[1802225]: [NOTICE]   (1802225) : Initializing new worker (1802227)
Aug 28 16:00:37 hybxvdka01 haproxy[1802227]: [NOTICE]   (1802227) : haproxy version is 3.2.0-e134140d282c
Aug 28 16:00:37 hybxvdka01 haproxy[1802227]: [NOTICE]   (1802227) : path to executable is /usr/sbin/haproxy
Aug 28 16:00:37 hybxvdka01 haproxy[1802227]: [WARNING]  (1802227) : config : Parsing [/etc/haproxy/haproxy.cfg:31]: backend 'k8s-master' has the same name as frontend 'k8s-master' declared at /etc/haproxy/hapro>
Aug 28 16:00:37 hybxvdka01 haproxy[1802227]: [WARNING]  (1802227) : config : parsing [/etc/haproxy/haproxy.cfg:33] : backend 'k8s-master' : 'option tcplog' directive is ignored in backends.
Aug 28 16:00:37 hybxvdka01 haproxy[1802225]: [NOTICE]   (1802225) : Loading success.
Aug 28 16:00:37 hybxvdka01 systemd[1]: Started HAProxy Load Balancer.
lines 1-19/19 (END)