HTTP Load Balancing

Install HAProxy to configure Load Balancing Server.

[1] Install HAProxy.

[root@futurelinux ~]# dnf install haproxy -y

[2] Configure HAProxy.

[root@futurelinux ~]# vi /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
...
...
# comment out all for existing [frontend ***] [backend ***] sections
# and add follows to the end

# define frontend ( any name is OK for [http-in] )
frontend http-in
    # listen 80 port
    bind *:80
    # set default backend
    default_backend    backend_servers
    # send X-Forwarded-For header
    option             forwardfor

# define backend
backend backend_servers
    # balance with roundrobin
    balance            roundrobin
    # define backend servers
    server             node01 10.0.0.51:80 check
    server             node02 10.0.0.52:80 check

[root@futurelinux ~]# systemctl enable haproxy
Created symlink /etc/systemd/system/multi-user.target.wants/haproxy.service β†’ /usr/lib/systemd/system/haproxy.service.
[root@futurelinux ~]# systemctl start haproxy

[3] If Firewalld is running, allow ports HAProxy listens.

[root@futurelinux ~]# firewall-cmd --permanent --add-service=http
success
[root@futurelinux ~]# firewall-cmd --reload
success