HAProxy를 실행하는 Fedora 22 서버에 SSL을 설정하려고 합니다. 구성( /etc/haproxy/haproxy.cfg
)은 다음과 같습니다.
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
tune.ssl.default-dh-param 2048
defaults
log global
mode http
option httplog
option dontlognull
option http-server-close
option forwardfor
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
frontend main
bind *:80
bind *:443 ssl crt /etc/haproxy/certificate.pem
redirect scheme https if !{ ssl_fc }
default_backend app
backend app
balance roundrobin
server app1 127.0.0.1:8000 check
이제 를 실행하면 systemctl restart haproxy && journalctl -u haproxy.service -f
다음 오류가 발생합니다.
Sep 13 15:39:31 fedora-server systemd[1]: Started HAProxy Load Balancer.
Sep 13 15:39:31 fedora-server systemd[1]: Starting HAProxy Load Balancer...
Sep 13 15:39:31 fedora-server haproxy-systemd-wrapper[15620]: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
Sep 13 15:39:31 fedora-server haproxy-systemd-wrapper[15620]: [ALERT] 255/153931 (15621) : parsing [/etc/haproxy/haproxy.cfg:30] : 'bind *:443' : unable to load SSL private key from PEM file '/etc/haproxy/certificate.pem'.
Sep 13 15:39:31 fedora-server haproxy-systemd-wrapper[15620]: [ALERT] 255/153931 (15621) : Error(s) found in configuration file : /etc/haproxy/haproxy.cfg
Sep 13 15:39:31 fedora-server haproxy-systemd-wrapper[15620]: [ALERT] 255/153931 (15621) : Proxy 'main': no SSL certificate specified for bind '*:443' at [/etc/haproxy/haproxy.cfg:30] (use 'crt').
Sep 13 15:39:31 fedora-server haproxy-systemd-wrapper[15620]: [ALERT] 255/153931 (15621) : Fatal errors found in configuration.
Sep 13 15:39:31 fedora-server haproxy-systemd-wrapper[15620]: haproxy-systemd-wrapper: exit, haproxy RC=256
서비스 구성은 다음과 같습니다.
# cat /usr/lib/systemd/system/haproxy.service
[Unit]
Description=HAProxy Load Balancer
After=syslog.target network.target
[Service]
EnvironmentFile=/etc/sysconfig/haproxy
ExecStart=/usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid $OPTIONS
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
그러나 서비스가 실행하려고 시도하는 명령을 복사할 수 있으며 제대로 작동합니다.
첫째, 수동으로 실행하면 작동합니다(서비스 구성에서 가져옴).
# whoami
root
# /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
이것은 또한 작동합니다(서비스 로그에서 가져온 것으로 분명히 haproxy-systemd-wrapper
다음을 실행합니다:
# whoami
root
# /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
명확히 하자면, 이러한 명령 중 하나를 루트로 수동으로 실행하면 해당 명령이 작동하고 SSL을 통해 내 사이트에 액세스할 수 있습니다.
따라서 서비스로 실행될 때 HAProxy가 인증서를 읽을 수 없다고 가정합니다.
지금까지 시도한 내용은 다음과 같습니다.
chown haproxy:haproxy /etc/haproxy/certificate.pem
- 사용자 및 그룹을 루트로 전환
haproxy.cfg
- 아래의 서비스 구성에
User=root
및 추가Group=root
[Service]
sudo -u haproxy /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
포트와 관련하여 다른 오류가 발생하므로 서비스에서 사용자 haproxy를 사용하지 않을 가능성이 높습니다. 그렇지 않으면 더 많은 오류가 발생합니다.
사용자 haproxy로 파일에 액세스할 수 있습니다 sudo -u haproxy cat /etc/haproxy/certificate.pem
.
편집하다:
귀하의 답변을 기반으로 업데이트된 서비스 구성은 다음과 같습니다.
[Unit]
Description=HAProxy Load Balancer
After=syslog.target network.target
SELinuxContext=unconfined_u:object_r:var_t:s0
지금 무슨 일이 일어나는거야:
Sep 13 17:51:21 ServiceName systemd[1]: Starting HAProxy Load Balancer...
Sep 13 17:51:21 ServiceName systemd[1]: haproxy.service: main process exited, code=exited, status=203/EXEC
Sep 13 17:51:21 ServiceName systemd[1]: Unit haproxy.service entered failed state.
Sep 13 17:51:21 ServiceName systemd[1]: haproxy.service failed.
내가 가치를 얻은 방법 SELinuxContext
:
# ls -lZ /etc/haproxy/certificate.pem
-rw-r--r--. 1 root root unconfined_u:object_r:var_t:s0 9245 Sep 13 17:43 /etc/haproxy/certificate.pem
답변1
당신은 Fedora를 사용하고 있습니다.SELinux. Systemd 서비스는 깨끗한 환경에서 실행됩니다.~ 아니다systemctl에 의해 직접 생성됩니다. 따라서 무엇보다도 다른 SELinux 컨텍스트에서 시작됩니다(기본값은 system_u:system_r:init_t:s0
?).
인증서 파일( ls -lZ
및 사용 chcon
)과 haproxy 프로세스(아마도 SELinuxContext=
systemd 장치에서 사용)에 대해 올바른 SELinux 컨텍스트가 설정되어 있는지 확인하세요.
id
귀하(또는 서비스)의 현재 컨텍스트를 보려면 실행해 보세요 .