我们可以通过 socat 命令 实现对 haproxy 的管理,包括获取监控数据,对后端服务器实现启动停止,服务流量控制等等。
要想 haproxy 支持通过 socat 来管理,需要在 haproxy.cfg 加入配置:
有两种方式,可以使用TCP或者Unix套接字进行访问:
global
# 启用TCP方式
stats socket ipv4@192.168.203.8:9999 level admin
# 启用UNIX套接字
stats socket /var/run/haproxy.sock mode 660 level admin
sudo yum install socat
在linux上获取HAProxy 的统计信息
Unix套接字:
echo "show stat" | socat stdio unix-connect:/var/run/haproxy.sock
TCP:
echo "show stat" | socat stdio tcp4-connect:192.168.203.8:9999
Unix套接字
socat stdio unix-connect:/var/run/haproxy.sock
回车
输入命令(show stat)
回车
TCP:
socat stdio tcp4-connect:192.168.203.8:9999
回车
输入命令(show stat)
回车
欢迎指出我的错误!