Configuration

HAproxy - 無法打開配置文件:權限被拒絕

  • April 13, 2019

我正在使用 HAproxy 作為負載均衡器進行一些測試。我也安裝並配置了它,甚至是帶有 rsyslog 的日誌。我檢查了配置 haproxy -c -f /etc/haproxy/haproxy.cnfhaproxy -d -f /etc/haproxy.cnf。一切似乎都很好,但是在啟動 haproxy 之後systemctl start haproxy,我執行systemctl status haproxy了,它向我展示了這個:

haproxy.service - HAProxy Load Balancer
  Loaded: loaded (/usr/lib/systemd/system/haproxy.service; enabled)
  Active: inactive (dead) since jue 2015-07-02 14:47:13 CDT; 7s ago
 Process: 29832 ExecStart=/usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid (code=exited, status=0/SUCCESS)
Main PID: 29832 (code=exited, status=0/SUCCESS)
systemd[1]: Started HAProxy Load Balancer.
haproxy-systemd-wrapper[29832]: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
haproxy-systemd-wrapper[29832]: [ALERT] 182/144713 (29833) : Could not open configuration file /etc/haproxy/haproxy.cfg : Permission denied
haproxy-systemd-wrapper[29832]: haproxy-systemd-wrapper: exit, haproxy RC=256

從邏輯上講,這必須指向文件權限,所以我對 haproxy.cnf 有 777 權限,結果相同。我測試 chown haproxy:haproxy,結果相同。

我有很多護目鏡,但我找不到解決這個問題的方法。

可能在 Selinux(如果您使用基於 Redhat 的發行版)或 apparmor(如果您使用 ubuntu)上存在一些錯誤配置。

嘗試阻止它們以驗證這是否是問題所在。您還可以嘗試使用執行 haproxy 守護程序的使用者使用以下命令讀取配置文件:

sudo -u <haproxy_user> cat /etc/haproxy/haproxy.cfg

引用自:https://serverfault.com/questions/703231