haproxy.当我在为网站服务的同一台机器上设置负载均衡器时,服务启动失败



我有两台机器

192.46.209.80 # server1
192.46.209.82 # server2

我正在同一台机器server1上设置HAProxy负载均衡器,这也为我的网站提供服务。因此,现在server1将运行HAProxy以及web服务器。我根据本教程设置了Apache2和HAProxy

192.46.209.80这是我的主机文件

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这是我的主机文件

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