HAProxy Management & Operations
Detailed guide on managing HAProxy instances, reloads, monitoring, and APIs.
Documentation
Hitless Reload
To achieve seamless reloads without losing connections using SIGUSR2 or the -x flag.
Configuration
# Enable stats socket for hitless reload
stats socket /var/run/haproxy.sock mode 600 expose-fd listeners level userExecution
# Graceful restart/reload using the previous process ID and the state socket
haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -sf $(cat /run/haproxy.pid) -x /var/run/haproxy.sockMonitoring & Stats
Check if Prometheus is supported:
haproxy -vv | grep 'Prometheus'Stats & Metrics Frontend
frontend stats
bind *:8404
mode http
option http-use-htx
# Prometheus metrics
http-request use-service prometheus-exporter if { path /metrics }
# Traditional stats page
stats enable
stats uri /stats
stats refresh 10sRuntime Commands
Interact with HAProxy via socket (requires socat):
echo "disable frontend website" | sudo socat stdio /run/haproxy.sockData Plane API
The Data Plane API allows dynamic configuration changes via REST.
Example setup
# Create a restart script for the API to call
echo -e '#!/bin/sh\nhaproxy -f haproxy.cfg -p haproxy.pid -sf $(cat haproxy.pid)' > hap-restart.sh
chmod +x hap-restart.sh
# Run Data Plane API
dataplaneapi --port 5555 -b $(which haproxy) -c haproxy.cfg -d 5 -r 'hap-restart.sh' \
-s 'haproxy -f haproxy.cfg -p haproxy.pid' -t /tmp/haproxy --userlist hap-dp
# Test API
curl -X GET --user dataplaneapi:mypassword http://localhost:5555/v2/info关联信息
反向链接、本文链接的其他页面和外部资料。
参考资料
GitHub1 条
- haproxytech/dataplaneapigithub.com/haproxytech/dataplaneapi
其他外链8 条
- cbonte.github.io/haproxy-dconv/2.2/management.htmlcbonte.github.io/haproxy-dconv/2.2/management.html
- grafana.com/grafana/dashboards/2428grafana.com/grafana/dashboards/2428
- www.haproxy.com/blog/exploring-the-haproxy-stats-pagewww.haproxy.com/blog/exploring-the-haproxy-stats-page
- www.haproxy.com/blog/haproxy-exposes-a-prometheus-metrics-endpointwww.haproxy.com/blog/haproxy-exposes-a-prometheus-metrics-endpoint
- www.haproxy.com/blog/hitless-reloads-with-haproxy-howtowww.haproxy.com/blog/hitless-reloads-with-haproxy-howto
- www.haproxy.com/blog/truly-seamless-reloads-with-haproxy-no-more-hackswww.haproxy.com/blog/truly-seamless-reloads-with-haproxy-no-more-hacks
- www.haproxy.com/documentation/hapee/2-1r1/configuration/dataplaneapiwww.haproxy.com/documentation/hapee/2-1r1/configuration/dataplaneapi
- www.haproxy.org/download/2.1/doc/management.txtwww.haproxy.org/download/2.1/doc/management.txt