在 HAProxy 程序管理器中安裝數據平面 API
我正在嘗試使用此處詳述的說明在 HAProxy 啟動時啟動數據平面 API:https ://www.haproxy.com/documentation/hapee/1-9r1/configuration/dataplaneapi/#using-the-haproxy-process-經理
我的問題是我明白了:
$ curl -X GET --user admin:mypassword "http://localhost:5555/v1/services/haproxy/info" {"code":500,"message":"dial unix unix@/run/haproxy-master.sock: connect: no such file or directory"}
這很奇怪,因為該文件存在於此處:
$ ls -lah /run/haproxy-master.sock srwxr-xr-x 1 root root 0 Jul 31 18:05 /run/haproxy-master.sock
並且該程序以 root 使用者身份執行,因此它應該能夠看到它:
$ sudo systemctl status haproxy.service [sudo] password for user: ● haproxy.service - HAProxy Load Balancer Loaded: loaded (/lib/systemd/system/haproxy.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2019-07-31 18:05:49 -05; 18h ago Docs: man:haproxy(1) file:/usr/share/doc/haproxy/configuration.txt.gz Process: 22227 ExecReload=/bin/kill -USR2 $MAINPID (code=exited, status=0/SUCCESS) Process: 22739 ExecReload=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS (code=exited, status=1/FAILURE) Process: 24307 ExecStartPre=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS (code=exited, status=0/SUCCESS) Main PID: 24335 (haproxy) Tasks: 12 (limit: 4418) CGroup: /system.slice/haproxy.service ├─24335 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /run/haproxy-master.sock ├─24339 dataplaneapi --host 0.0.0.0 --port 5555 --haproxy-bin /usr/sbin/haproxy --config-file /etc/haproxy/haproxy.cfg --reload-cmd systemctl reload haproxy --reload-delay 5 --userlist controller └─24341 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /run/haproxy-master.sock Jul 31 18:05:47 lb01.private systemd[1]: Starting HAProxy Load Balancer... Jul 31 18:05:48 lb01.private haproxy[24335]: [WARNING] 211/180548 (24335) : parsing [/etc/haproxy/haproxy.cfg:33]: 'option httplog' overrides previous 'log-format' in 'defaults' section. Jul 31 18:05:48 lb01.private haproxy[24335]: [WARNING] 211/180548 (24335) : parsing [/etc/haproxy/haproxy.cfg:117]: keyword 'forceclose' is deprecated in favor of 'httpclose', and will not be supported by future versions. Jul 31 18:05:49 lb01.private haproxy[24335]: [NOTICE] 211/180548 (24335) : New program 'api' (24339) forked Jul 31 18:05:49 lb01.private haproxy[24335]: [NOTICE] 211/180548 (24335) : New worker #1 (24341) forked Jul 31 18:05:49 lb01.private systemd[1]: Started HAProxy Load Balancer. Jul 31 18:05:51 lb01.private haproxy[24335]: dial unix unix@/run/haproxy-master.sock: connect: no such file or directory Jul 31 18:06:40 lb01.private haproxy[24335]: dial unix unix@/run/haproxy-master.sock: connect: no such file or directory Aug 01 12:36:07 lb01.private haproxy[24335]: dial unix unix@/run/haproxy-master.sock: connect: no such file or directory
以下是我認為我的 haproxy.cfg 文件的相關位是:
global stats socket /run/haproxy.sock user haproxy group haproxy mode 660 level admin userlist controller user admin insecure-password mypassword program api command dataplaneapi --host 0.0.0.0 --port 5555 --haproxy-bin /usr/sbin/haproxy --config-file /etc/haproxy/haproxy.cfg --reload-cmd "systemctl reload haproxy" --reload-delay 5 --userlist controller
我完全理解“stats socket”聲明說 /run/haproxy.sock,我嘗試將其更改為 /run/haproxy-master.sock 並重新啟動它。同樣的錯誤。不確定 haproxy-master.sock 文件來自哪裡,猜測它是預設的嗎?
/run/haproxy-master.sock
當 systemd 執行 haproxy 時作為套接字啟動:24335 usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /run/haproxy-master.sock
如果未在命令行上配置,
dataplaneapi
則使用從主程序傳遞給子程序的環境變數(特別是從HAPROXY_MWORKER
和HAPROXY_MASTER_CLI
變數)獲取它。為什麼它無法閱讀它超出了我的範圍。
遇到了同樣的問題…
似乎這受 systemd 預設的影響。觀察到,當直接從 cli 啟動 haproxy 時沒有其他參數,問題就消失了。
# grep PRETTY /etc/os-release PRETTY_NAME="Ubuntu 18.04.3 LTS" # systemctl cat haproxy.service | grep sock Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid" "EXTRAOPTS=-S /run/haproxy-master.sock" # haproxy -d -f /etc/haproxy/haproxy.cfg
當 haproxy 從 cli 啟動或使用 systemd 啟動時,您可以通過比較活動的 unix 套接字來驗證這一點
# netstat -axe | grep haproxy.*sock
相應地進行更改:)