在 HAProxy 进程管理器中安装数据平面 API

在 HAProxy 进程管理器中安装数据平面 API

我正在尝试使用此处详细说明在 HAProxy 启动时启动数据平面 API:https://www.haproxy.com/documentation/hapee/1-9r1/configuration/dataplaneapi/#using-the-haproxy-process-manager

我的问题是:

$ 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 文件来自哪里,猜测它是默认文件?

答案1

/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使用从主进程传递给子进程的环境变量(特别是 fromHAPROXY_MWORKERHAPROXY_MASTER_CLI变量)来获取它。为什么它无法读取它,我不明白。

答案2

遇到了同样的问题...

似乎这受 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 启动时的活动 unix 套接字来验证这一点,或者使用 systemd

# netstat -axe  | grep haproxy.*sock

做出相应的改变:)

答案3

其余两个答案都正确,但缺少解决方案。

编辑/lib/systemd/system/haproxy.service 注释掉EXTRA_PARAMETERS,即

Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid"
# "EXTRAOPTS=-S /run/haproxy-master.sock"

跑步systemctl daemon-reload

跑步systemctl restart haproxy

相关内容