Search code examples
apacheserverload-balancinghaproxyhosts

haproxy.service start failed when I set up load balancer on the same machine which serves the website


I have 2 machines

192.46.209.80 # server1
192.46.209.82 # server2

I was setting up HAProxy load balancer on the same machine server1 which is also serving my website. So now server1 will be running HAProxy as well as the webserver. I setup Apache2 and HAProxy according to this tutorial

On 192.46.209.80 server1 this is my hosts file

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

On 192.46.209.82 server2 this is my hosts file

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

then after installing HAProxy on server1

sudo sudo apt install haproxy

I edited and appended in 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

After running

sudo systemctl restart haproxy.service

I am getting error

Job for haproxy.service failed because the control process exited with error code.
See "systemctl status haproxy.service" and "journalctl -xe" for details.

This is the result of 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.

Solution

  • Since my Apache web server is listening on Port 80, therefore I cannot configure the same for my HAProxy.

    Changed it to another port and it worked.

    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