Appearance
故障排查与常见错误
HAProxy 故障排查的常用方法和典型错误解决方案。
查看 HAProxy 日志
bash
journalctl -u haproxy -f
tail -f /var/log/haproxy/haproxy.log常用诊断命令
bash
# 测试配置
haproxy -c -f /etc/haproxy/haproxy.cfg
# 查看状态
socat /run/haproxy-admin.sock stdio << EOF
show stat
show backend
show server state
show errors
EOF常见错误与解决方案
1. backend has no server available!
原因: 所有后端服务器都下线
解决: 检查服务器状态和健康检查
2. SSL handshake error
原因: 证书问题、协议不兼容
解决: 检查证书配置,启用合适的 TLS 版本
3. 503 Service Unavailable
原因: 所有后端都不可用
解决: 检查后端健康状态和超时设置
4. could not bind to socket
原因: 端口被占用、权限不足
解决: 检查端口占用和 SELinux 设置
性能问题排查
bash
# 检查后端响应时间
echo "show stat" | socat /run/haproxy-admin.sock stdio
# 查看当前连接
echo "show sess" | socat /run/haproxy-admin.sock stdio | wc -l调试模式
bash
# 前台运行
haproxy -f /etc/haproxy/haproxy.cfg -d诊断检查清单
| 检查项 | 命令 |
|---|---|
| 运行状态 | systemctl status haproxy |
| 配置文件 | haproxy -c -f /etc/haproxy/haproxy.cfg |
| 端口监听 | ss -tlnp | grep haproxy |
| 后端状态 | echo "show server state" | socat /run/haproxy-admin.sock stdio |
| 错误日志 | grep -i error /var/log/haproxy/haproxy.log |