Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

How to Install and Configure HAProxy on CentOS 10 for Load Balancing & High Availability

  • March 26, 2025
  • 15 min read
IT Engineer and Technical Author. Karim is specializing in Linux, he is a prolific blogger who writes for various websites.
IT Engineer and Technical Author. Karim is specializing in Linux, he is a prolific blogger who writes for various websites.

HAProxy with the Keepalived software package is the best option for configuring load balancing and high availability on Linux-based CentOS 10. It ensures efficient traffic distribution between servers and improves performance and reliability.

Furthermore, HAProxy supports various load-balancing algorithms, including round-robin and more.

It also provides high availability by detecting server failures and rerouting traffic to active and healthy servers.

Keepalived is a free software package best suited for high availability and load balancing on Linux systems, such as CentOS 10. It efficiently monitors server health and automatically reroutes traffic to healthy and active nodes.

This article presents you with how to install HAProxy on CentOS 10 and configure it for load balancing and high availability.

Configuring HAProxy for Efficient Load Balancing

To configure the HAProxy software, install the following necessary packages on your CentOS 10.

Step 1: System Information

Run the command from your CentOS 10 command prompt to verify your operating system:

sudo yum install epel-release -y

 

System Information

 

This step will help you install the correct and compatible software packages for your system.

Step 2: Access Up to Date Packages 

In CentOS, you can access the latest and up-to-date software packages through the “epel-release”. Install it on your CentOS 10 with the command:

sudo yum install epel-release -y

 

Access Up to Date Packages

 

A confirmation message will appear on your prompt screen after completing the installation process.

Step 3: Installs Essential Dependencies 

For the smooth running of the HAProxy on CentOS 10, install the following essential dependencies:

sudo yum install curl gcc openssl-devel libnl3-devel net-snmp-devel -y

 

Installs Essential Dependencies

 

You have already installed the necessary dependencies, you will see the above message on your screen.

Step 4: Install Nginx (Optional)

For practical demonstration, we will use the Nginx. Use the following command to install the Nginx on your CentOS 10:

sudo yum install nginx -y

 

Install Nginx (Optional) A screenshot of a computer program Description automatically generated

 

Note: Nginx is optional, you can skip installing it on your system.

Step 5: Start and Enable Nginx

To properly run the Nginx package, utilize the following script to enable and start it on your CentOS 10:

sudo systemctl start nginx && systemctl enable nginx

 

Start and Enable Nginx

 

If you see the message mentioned above in the output, it indicates that the Nginx service has been started on your machine.

Step 6: Check Nginx Status

You can double-check the status of Nginx on your machine using the command:

sudo systemctl status nginx

 

A screenshot of a computer program Description automatically generated

 

You can see that the Nginx service is enabled and running correctly.

Step 7: Set Up a Test Page

Now, let’s create a simple test page to confirm that the Nginx package is working:

echo "Welcome to $HOSTNAME" | sudo tee /usr/share/nginx/html/index.html

 

Set Up a Test Page

 

If the command returns the hostname (e.g. KarimSys1), it means that Nginx has been successfully configured on your CentOS 10 system.

Install HAProxy on CentOS 10

The following steps contribute to setting up HAProxy on the latest CentOS 10 system.

Step 1: Install HAProxy

The HAProxy software package can be installed from the CentOS official repository. Here is the command:

sudo yum install haproxy -y

 

Install HAProxy A screenshot of a computer program Description automatically generated

 

At the time of installation, the latest version of HAProxy is 3.0.5 for CentOS.

Step 2: Create HAProxy Configuration Backup

Before making any modifications to the HAProxy configuration file, first create a backup file:

sudo cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak

 

Create HAProxy Configuration Backup

 

This step saves the default HAProxy configuration for the future.

Step 3: Check IP Address

With the following code, inspect your system’s server IP address:

ip a

 

Check IP Address

 

Without the correct server IP address, you cannot configure HAProxy correctly.

Step 4: Configure HAProxy on CentOS

Let’s modify the HAProxy configuration file according to your needs. For instance, define frontend and backend settings:

sudo nano /etc/haproxy/haproxy.cfg

 

Configure HAProxy on CentOS

 

Frontend settings:

frontend main
bind *:8080
stats enable
stats uri /stats
default_backend main_app

 

Frontend settings

 

Backend settings:

backend main_app
balance roundrobin
server Test_app1 192.168.122.63:8080 check
server Test_app2 192.168.122.64:8080 check

 

Backend settings

 

You can add multiple server IP addresses in the backend settings for load balancing.

Step 5: Start the HAProxy Service

After successfully modifying the configuration file, start the HAProxy service with the following command:

sudo systemctl start haproxy && sudo systemctl enable haproxy

 

Start the HAProxy Service

 

Once you have enabled and started the HAProxy services on your CentOS 10, proceed to the next step.

Step 6: Reload System Firewall

Run the command to reload the Firewall settings on your CentOS 10:

sudo firewall-cmd --reload

 

Reload System Firewall

 

If the command prints the “success” on your prompt, it shows that all ports are open.

Step 7: Test HAProxy Configuration

You can also test the HAProxy configuration for its syntax error using the command:

sudo haproxy -f /etc/haproxy/haproxy.cfg -c

 

Test HAProxy Configuration

 

The empty output indicates that there is no syntax error in the HAProxy configuration file. The HAProxy has been configured on your CentOS 10.

Install Keepalived for High Availability on CentOS 10

With the below steps set up Keepalived for High Availability on CentOS 10.

Step 1: Install the Keepalived Package 

To ensure high availability on your CentOS 10, install the Keepalived package from system repository:

sudo yum install keepalived -y

 

Install the Keepalived Package  A screenshot of a computer Description automatically generated

 

As shown above, Keepalived 2.2.8 has been installed on your CentOS 10 without encountering any error.

Step 2: Configure the Keepalived Setting

Access the Keepalived configuration file to set up a backup system:

sudo nano /etc/keepalived/keepalived.conf

 

Configure the Keepalived Setting

 

You can make the necessary changes in the file. In our case, we have commented the vrrp_strict, vrrp_garp_interval, and vrrp_gna_interval to 1:

 

Configure the Keepalived Setting

Also, modify the following lines:

vrrp_instance VI_1 {
state MASTER
interface ens3
virtual_router_id 51
priority 101
advert_int 1

authentication {
auth_type PASS
auth_pass mysecurepass
}

virtual_ipaddress {
192.168.122.103
}
}

 

modify the following lines

 

While editing the Keepalived configuration file, make sure you have entered the correct information of interface, priority, and virual_ipaddress.

Step 3: Start the Keepalived Service

After making the required change in the configuration file, run the command to start the Keepalived service on your CentOS 10:

sudo systemctl start keepalived && sudo systemctl enable keepalived

 

Start the Keepalived Service

 

Till now, you have successfully configured the Keepalived software package on your system.

Step 4: Check Keepalived Status

Let’s verify that the Keepalived service is running properly:

sudo systemctl status keepalived

 

Check Keepalived Status

 

Step 5: Inspect the IP Address

To confirm that the virtual IP address is assigned, use the below command:

ip a

 

Inspect the IP Address

 

In the above-mentioned screenshot, you can see that the virtual IP address “192.168.122.103” has been assigned successfully.

Step 6: Access the Load Balancer and High Availability

You can now test that HAProxy and Keepalived configuration is working correctly by accessing the following URLs:

http://192.168.122.63
http://192.168.122.103
http://192.168.122.64

 

Access the Load Balancer and High Availability

 

Keepalived has detected that the IP 192.168.122.64 (KarimSys1) is down. But, the Virtual IP address “192.168.122.103” is still accessible by switching traffic to the working server (192.168.122.63).

 

Access the Load Balancer and High Availability

 

HAProxy has been configured on your CentOS 10 to load balance and route traffic to the available backend servers.

Step 7: Access the Load Balancer Statistics 

You can view the graphical statistics report of the load balancer using the following URL:

http://192.168.122.103:8080/stats

 

Access the Load Balancer Statistics 

 

The above dashboard provides a detailed statistical report of the HAProxy configuration on your CentOS 10 system.

FAQs

Can I install HAProxy on CentOS 10?

Yes, you can set up the HAProxy on your latest CentOS 10 machine. To install the HAProxy software package run the commands:

sudo yum install haproxy -y

sudo systemctl enable haproxy && sudo systemctl start haproxy

How to configure HAProxy for Load Balancing and High Availability on CentOS 10?

To modify the configuration file for load balancing and high availability, access this file:

/etc/haproxy/haproxy.cfg.

In this file, define the backend and frontend settings according to your requirements and restart the HAProxy service.

What is the best software for High Availability on CentOS 10?

Keepalived is one of the popular software for achieving High Availability on CentOS 10.

How can I install the Keepalived software package for High Availability on CentOS 10?

You can configure the Keepalived package on your CentOS 10 using the following commands:

sudo yum install keepalived -y

How to test the Configuration file for HAProxy on CentOS 10?

After configuring the HAProxy and Keepalived on your CentOS 10, you can test the file using the command:

sudo haproxy -f /etc/haproxy/haproxy.cfg -c

Conclusion

The HAProxy software package can be installed on the latest CentOS 10 machine with easy steps. For load balancing and high availability, you can easily configure it on your machine. To install HAProxy, use the command: sudo yum install haproxy, while for high availability install the keepalived (sudo yum install keepalived) on your CentOS 10.

Hey! Found Karim’s article helpful? Looking to deploy a new, easy-to-manage, and cost-effective hyperconverged infrastructure?
Alex Bykovskyi
Alex Bykovskyi StarWind Virtual HCI Appliance Product Manager
Well, we can help you with this one! Building a new hyperconverged environment is a breeze with StarWind Virtual HCI Appliance (VHCA). It’s a complete hyperconverged infrastructure solution that combines hypervisor (vSphere, Hyper-V, Proxmox, or our custom version of KVM), software-defined storage (StarWind VSAN), and streamlined management tools. Interested in diving deeper into VHCA’s capabilities and features? Book your StarWind Virtual HCI Appliance demo today!