23rd April 2024

HAProxy is a free open-source load balancer, a high-performance, and proxy server for TCP and HTTP-based functions. It distributes the workload between the net and utility servers. It’s particularly developed for high-traffic web sites to enhance efficiency, availability, and redundancy.

Due to Haproxy’s reliability, effectivity, and low reminiscence and CPU footprint, it’s broadly used for load balancing. Load balancing is a well-liked answer to distribute internet functions horizontally throughout a number of servers whereas offering customers with a single level of entry to the service.

Allow us to see the way to set up and configure HAProxy load balancing with two internet servers on Debian 11.

Replace the Debian System

Earlier than putting in any software program, make sure that your system makes use of the newest out there software program packages in your Debian system

sudo apt replace 
sudo apt -y improve

As soon as accomplished, restart the server

sudo reboot

Set up Apache Backend Servers

Now we’ll arrange two backend Apache servers. To put in and configure the Apache bundle, run the next instructions:

sudo apt set up apache2

After the apache2 set up, use the under command to predefine message in index.html

Server 1:

echo "<H1>Howdy from Apache Server1</H1>" | sudo tee /var/www/html/index.html

Server 2:

echo "<H1>Howdy from Apache Server2</H1>" | sudo tee /var/www/html/index.html

Word: This step is optionally available if you happen to want to use HAProxy with out Apache.

Set up HAProxy on Debian 11

To put in HAProxy, run the under command on each the servers:

sudo apt -y set up haproxy

Configure HAProxy as a load balancer

Now, arrange HAproxy to make use of a round-robin stability between the 2 servers.

Open the file /and so on/haproxy/haproxy.cfg and add the next configuration. Then, save and shut your file.

frontend apache_front
        # Frontend hear port - 80
        bind *:80
        # Set the default backend
        default_backend    apache_backend_servers
        # Allow ship X-Forwarded-For header
        choice             forwardfor

 

# Outline backend
backend apache_backend_servers                                                                                                                     
        # Use roundrobin to stability visitors
        stability            roundrobin
        # Outline the backend servers
        server             backend01 192.168.10.20:80 verify
        server             backend02 192.168.10.21:80 verify

Restart HAProxy on each servers by following these steps:

sudo systemctl restart haproxy

As soon as the configuration is accomplished, then open your internet browser and enter the URL http://your-haproxy-ip-address. After every refresh, HAProxy will ship requests to backend servers one after the other.

Configure SSL

Mix a non-public key and a certificates file with the next command:

cat fullchain.pem privkey.pem > haproxy.pem

Subsequent, configure the HAProxy to make use of the SSL certificates on the entrance finish.

frontend apache-frontend
        bind *:80
        bind *:443 ssl crt /and so on/letsencrypt/dwell/webapp.computingforgeeks.com/haproxy.pem

 

You will have now efficiently put in and configured the HAProxy load-balancing server. This can assist to extend your internet server efficiency.

Additionally, verify: HAProxy vs NGINX for Load Balancing

To get extra updates you’ll be able to comply with us on Fb, Twitter, LinkedIn

Subscribe to get free weblog content material to your Inbox

Written by actsupp-r0cks

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.