haproxy.service 当我在为网站提供服务的同一台机器上设置负载平衡器时启动失败
haproxy.service start failed when I set up load balancer on the same machine which serves the website
我有2台机器
192.46.209.80 # server1
192.46.209.82 # server2
我在同一台机器 server1 上设置了 HAProxy 负载平衡器,它也为我的网站提供服务。
所以现在 server1 将是 运行 HAProxy 以及网络服务器。
我根据这个 tutorial
设置 Apache2 和 HAProxy
在 192.46.209.80 server1 这是我的 hosts 文件
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
HAproxy 192.46.209.80
192.46.209.80 HAProxy
192.46.209.80 server1
192.46.209.82 server2
在 192.46.209.82 server2 这是我的 hosts 文件
127.0.0.1 localhost
The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
HAproxy 192.46.209.80
然后在 server1 上安装 HAProxy 之后
sudo sudo apt install haproxy
我编辑并附加在 sudo nano /etc/haproxy/haproxy.cfg
#HAProxy for web servers
frontend web-frontend
bind 192.46.209.80:80
mode http
default_backend web-backend
backend web-backend
balance roundrobin
server server1 192.46.209.80 check port 80
server server2 192.46.209.82 check port 80
运行
之后
sudo systemctl restart haproxy.service
我遇到错误
Job for haproxy.service failed because the control process exited with error code.
See "systemctl status haproxy.service" and "journalctl -xe" for details.
这是journalctl -xe
的结果
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- An ExecStart= process belonging to unit haproxy.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 1.
Oct 19 14:13:18 localhost systemd[1]: haproxy.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit haproxy.service has entered the 'failed' state with result 'exit-code'.
Oct 19 14:13:18 localhost systemd[1]: Failed to start HAProxy Load Balancer.
-- Subject: A start job for unit haproxy.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit haproxy.service has finished with a failure.
--
-- The job identifier is 6245 and the job result is failed.
Oct 19 14:13:18 localhost systemd[1]: haproxy.service: Scheduled restart job, restart counter is at 5.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Automatic restarting of the unit haproxy.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
Oct 19 14:13:18 localhost systemd[1]: Stopped HAProxy Load Balancer.
-- Subject: A stop job for unit haproxy.service has finished
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A stop job for unit haproxy.service has finished.
--
-- The job identifier is 6314 and the job result is done.
Oct 19 14:13:18 localhost systemd[1]: haproxy.service: Start request repeated too quickly.
Oct 19 14:13:18 localhost systemd[1]: haproxy.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit haproxy.service has entered the 'failed' state with result 'exit-code'.
Oct 19 14:13:18 localhost systemd[1]: Failed to start HAProxy Load Balancer.
-- Subject: A start job for unit haproxy.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit haproxy.service has finished with a failure.
--
-- The job identifier is 6314 and the job result is failed.
由于我的 Apache Web 服务器正在侦听端口 80,因此我无法为我的 HAProxy 配置相同的端口。
将其更改为另一个端口并且它有效。
frontend web-frontend
bind 192.46.209.80:541
mode http
default_backend web-backend
backend web-backend
balance roundrobin
server server1 192.46.209.80 check port 80
server server2 192.46.209.82 check port 80
我有2台机器
192.46.209.80 # server1
192.46.209.82 # server2
我在同一台机器 server1 上设置了 HAProxy 负载平衡器,它也为我的网站提供服务。 所以现在 server1 将是 运行 HAProxy 以及网络服务器。 我根据这个 tutorial
设置 Apache2 和 HAProxy在 192.46.209.80 server1 这是我的 hosts 文件
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
HAproxy 192.46.209.80
192.46.209.80 HAProxy
192.46.209.80 server1
192.46.209.82 server2
在 192.46.209.82 server2 这是我的 hosts 文件
127.0.0.1 localhost
The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
HAproxy 192.46.209.80
然后在 server1 上安装 HAProxy 之后
sudo sudo apt install haproxy
我编辑并附加在 sudo nano /etc/haproxy/haproxy.cfg
#HAProxy for web servers
frontend web-frontend
bind 192.46.209.80:80
mode http
default_backend web-backend
backend web-backend
balance roundrobin
server server1 192.46.209.80 check port 80
server server2 192.46.209.82 check port 80
运行
之后sudo systemctl restart haproxy.service
我遇到错误
Job for haproxy.service failed because the control process exited with error code.
See "systemctl status haproxy.service" and "journalctl -xe" for details.
这是journalctl -xe
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- An ExecStart= process belonging to unit haproxy.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 1.
Oct 19 14:13:18 localhost systemd[1]: haproxy.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit haproxy.service has entered the 'failed' state with result 'exit-code'.
Oct 19 14:13:18 localhost systemd[1]: Failed to start HAProxy Load Balancer.
-- Subject: A start job for unit haproxy.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit haproxy.service has finished with a failure.
--
-- The job identifier is 6245 and the job result is failed.
Oct 19 14:13:18 localhost systemd[1]: haproxy.service: Scheduled restart job, restart counter is at 5.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Automatic restarting of the unit haproxy.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
Oct 19 14:13:18 localhost systemd[1]: Stopped HAProxy Load Balancer.
-- Subject: A stop job for unit haproxy.service has finished
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A stop job for unit haproxy.service has finished.
--
-- The job identifier is 6314 and the job result is done.
Oct 19 14:13:18 localhost systemd[1]: haproxy.service: Start request repeated too quickly.
Oct 19 14:13:18 localhost systemd[1]: haproxy.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit haproxy.service has entered the 'failed' state with result 'exit-code'.
Oct 19 14:13:18 localhost systemd[1]: Failed to start HAProxy Load Balancer.
-- Subject: A start job for unit haproxy.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit haproxy.service has finished with a failure.
--
-- The job identifier is 6314 and the job result is failed.
由于我的 Apache Web 服务器正在侦听端口 80,因此我无法为我的 HAProxy 配置相同的端口。
将其更改为另一个端口并且它有效。
frontend web-frontend
bind 192.46.209.80:541
mode http
default_backend web-backend
backend web-backend
balance roundrobin
server server1 192.46.209.80 check port 80
server server2 192.46.209.82 check port 80