Skip to main content

HAProxy

caution
  • 不能转发任意 UDP - Nginx 可以
    • 2.3+ 支持 syslog UDP
    • 2.5+ 支持 QUIC, HTTP/3
    • 未来可能支持 DNS
haproxy -c -f haproxy.cfg # 检查配置是否正确
haproxy -f haproxy.cfg # 启动
# master-worker mode - reload
# 本质也是 -sf 启新的进程
kill -USR2 $(cat /var/run/haproxy.pid)

# 重启新的 haproxy - reload
haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid)
docker
docker run --rm -it \
-v /path/to/etc/haproxy:/usr/local/etc/haproxy:ro \
--sysctl net.ipv4.ip_unprivileged_port_start=0 \
--name haproxy haproxy:2.5

# reload
docker kill -s HUP haproxy

metrics

Runtime API

global
stats socket ipv4@127.0.0.1:9999 level admin
stats socket /run/haproxy-runtime-api.sock mode 666 level admin
stats timeout 2m
echo "help" | socat stdio tcp4-connect:127.0.0.1:9999
echo "show acl" | socat stdio /run/haproxy-runtime-api.sock
socat readline /run/haproxy-runtime-api.sock
help

Connect() failed for backend : no free ports

cat /proc/sys/net/ipv4/ip_local_port_range

echo "2000 60999" | sudo tee /proc/sys/net/ipv4/ip_local_port_range
  • 尝试添加 resolve-prefer ipv4