HAProxy cheatsheet
Service and config
| Command | Description |
|---|---|
systemctl status haproxy | Service status |
systemctl reload haproxy | Reload config (graceful) |
haproxy -c -f /etc/haproxy/haproxy.cfg | Validate config syntax |
haproxy -vv | Version and build info |
Stats and monitoring
| Command / URL | Description |
|---|---|
echo "show stat" | socat stdio /run/haproxy/admin.sock | Stats via socket |
echo "show info" | socat stdio /run/haproxy/admin.sock | Runtime info |
http://host:8404/stats | Stats web UI (if enabled) |
journalctl -u haproxy -f | Follow service logs |
ss -tlnp | grep haproxy | Check listeners |
Runtime socket commands
To query the socket non-interactively from your terminal bash command line, pipe your command string straight into the socat network utility, for example: echo "show info" | sudo socat stdio unix-connect:/var/run/haproxy.sock
| Command | Description |
|---|---|
show servers state <backend> | Server UP/DOWN state |
disable server <backend>/<server> | Drain a server |
enable server <backend>/<server> | Re-enable a server |
show errors | Recent HAProxy errors |
Minimal HTTP load balancer
global
log /dev/log local0
maxconn 4096
defaults
log global
mode http
option httplog
timeout connect 5s
timeout client 50s
timeout server 50s
frontend http_front
bind *:80
default_backend app_servers
backend app_servers
balance roundrobin
option httpchk GET /health
server app1 10.0.1.10:8080 check
server app2 10.0.1.11:8080 check
ACL routing example
frontend http_front
bind *:80
acl is_api path_beg /api
use_backend api_servers if is_api
default_backend web_servers
Pro tips
- Always
haproxy -cbeforereload— bad config can stop the daemon - Check the stats page first when backends show DOWN — health check path may be wrong
- Use
option forwardforso backends see real client IPs - Drain servers with
disable serverbefore maintenance, then re-enable
Practice scenarios
Hands-on HAProxy scenarios on live Linux VMs: haproxy