Haproxy两个进程由systemd创建

Haproxy两个进程由systemd创建

我刚刚编译了最新的Haproxy

[root@proxy system]# haproxy -v
HA-Proxy version 1.8.8 2018/04/19
Copyright 2000-2018 Willy Tarreau <[email protected]>

我的服务文件如下所示

[Unit]
Description=HAProxy Load Balancer
After=network.target

[Service]
Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid"
ExecStartPre=/usr/sbin/haproxy -f $CONFIG -c -q
ExecStart=/usr/sbin/haproxy -Ws -f $CONFIG -p $PIDFILE
ExecReload=/usr/sbin/haproxy -f $CONFIG -c -q
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=always
Type=notify

# The following lines leverage SystemD's sandboxing options to provide
# defense in depth protection at the expense of restricting some flexibility
# in your setup (e.g. placement of your configuration files) or possibly
# reduced performance. See systemd.service(5) and systemd.exec(5) for further
# information.

# NoNewPrivileges=true
# ProtectHome=true
# If you want to use 'ProtectSystem=strict' you should whitelist the PIDFILE,
# any state files and any other files written using 'ReadWritePaths' or
# 'RuntimeDirectory'.
# ProtectSystem=true
# ProtectKernelTunables=true
# ProtectKernelModules=true
# ProtectControlGroups=true
# If your SystemD version supports them, you can add: @reboot, @swap, @sync
# SystemCallFilter=~@cpu-emulation @keyring @module @obsolete @raw-io

[Install]
WantedBy=multi-user.target

但是当我启动服务时它会创建两个这样的过程

[root@proxy system]# systemctl status haproxy
● haproxy.service - HAProxy Load Balancer
   Loaded: loaded (/etc/systemd/system/haproxy.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2018-05-09 14:17:59 EDT; 2min 25s ago
  Process: 1350 ExecStartPre=/usr/sbin/haproxy -f $CONFIG -c -q (code=exited, status=0/SUCCESS)
 Main PID: 1352 (haproxy)
   CGroup: /system.slice/haproxy.service
           ├─1352 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
           └─1354 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid

May 09 14:17:59 proxy.loadbalancer systemd[1]: Starting HAProxy Load Balancer...
May 09 14:17:59 proxy.loadbalancer systemd[1]: Started HAProxy Load Balancer.

它应该这样工作吗或者我的配置无效?

谢谢

答案1

systemd 创建两个进程

这是不正确的。systemd创建一个进程,然后 haproxy 分叉(从而创建另一个进程)。这是正常的。这样做的原因之一是出于安全考虑。haproxy 以 root 身份启动并执行所需的最少设置工作(例如,绑定到端口 80)。然后它以用户身份运行,分叉并放弃特权haproxy

相关内容