HTTP Load Balancing

Install HAProxy to configure Load Balancing Server.

[1] Install HAProxy.

[[email protected] ~]# dnf install haproxy -y

[2] Configure HAProxy.

[[email protected] ~]# 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

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

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

[[email protected] ~]# firewall-cmd --permanent --add-service=http
success
[[email protected] ~]# firewall-cmd --reload
success