How to set up load balancing on CentOS 7 / Redhat 7 Linux using Apache.

Published: December 1, 2025 (Updated: Dec 1, 2025)

Enjoying this content? Subscribe to the Channel!

Master Active-Active Load Balancing on CentOS 7/RHEL 7 with Apache (Step-by-Step Guide!)

Hey tech enthusiasts, welcome back to Darren’s Tech Tutorials!

Load balancing is an absolutely essential skill for building resilient and scalable websites. By using an active-active setup, you ensure that traffic is evenly distributed across multiple servers, preventing bottlenecks and providing instant failover should one server go down.

In this comprehensive guide, we’re going to walk through how to configure robust Active-Active load balancing using Apache on CentOS 7 (this tutorial works perfectly for Red Hat Enterprise Linux 7, too!). By the end, you’ll have a high-availability setup directing traffic between two CentOS web servers.

Note: All commands referenced in this tutorial can be copied directly from the official link provided on the channel: https://darrenoneill.eu/?p=373


Prerequisites and Server Setup

To follow along successfully, you need three separate CentOS 7 virtual machines (or servers):

  1. Load Balancer Server (CentOS 7): This machine will run Apache and manage the traffic distribution.
  2. Web Server 1 (CentOS 7): Our first back-end server.
  3. Web Server 2 (CentOS 7): Our second back-end server.

Make sure you have both CentOS 7 and Apache installed on all three machines. If you need help getting set up, check out my tutorials on installing CentOS 7 and installing Apache.

Configuring Your Test Web Servers

To confirm that our load balancing is working correctly, we need to make sure Web Server 1 and Web Server 2 display unique content. We’ll edit the index.html file on each server.

1. Web Server 1 Configuration

On your first web server, use vi to edit the root Apache file:

sudo vi /var/www/html/index.html

Press i to enter insert mode and add the following line (or similar unique text):

This is Server 1. Howdy!

Save and exit by pressing Escape, then typing :wq!.

2. Web Server 2 Configuration

Now, jump over to your second web server and repeat the process, but change the text:

sudo vi /var/www/html/index.html

Add the unique content:

This is Server 2. Howdy!

Save and exit.

Quick Check: Open a browser on each web server and navigate to localhost. You should see the distinct messages, confirming Apache is running and the files are correct!

Opening the Firewall Ports (Crucial Step!)

To ensure the Load Balancer can communicate with the Web Servers, and that external users can access the Load Balancer, we must permanently open TCP Port 80 on all three servers.

Run the following command on the Load Balancer, Web Server 1, and Web Server 2:

sudo firewall-cmd --zone=public --add-port=80/tcp --permanent

After successfully running that command on all three machines, you must reload the firewall to apply the changes immediately:

sudo firewall-cmd --reload

Verifying Apache Load Balancing Modules

Before we create the configuration file, we need to ensure the necessary Apache proxy modules are enabled on the Load Balancer Server. If you installed Apache using the standard package manager on CentOS, these modules are usually enabled by default.

The key modules needed are: mod_proxy, mod_proxy_http, mod_proxy_balancer, and mod_lbmethod_byrequests.

You can check their status by examining the configuration file:

sudo vi /etc/httpd/conf.modules.d/00-proxy.conf

Inside this file, ensure that the lines loading these modules (starting with LoadModule) are not commented out (i.e., they do not have a # symbol in front of them).

Once verified, exit the file.

Creating the Load Balancer Configuration File

This is the “meat” of the tutorial. We will create a new configuration file on the Load Balancer Server to define how Apache should handle incoming requests and distribute them.

Create the file using the following command:

sudo vi /etc/httpd/conf.d/default-site.conf

Now, paste the following configuration block into the file. You must replace the placeholder IP addresses with the actual IP addresses of your Web Server 1 and Web Server 2.

In our tutorial setup, the web servers were on IPs ending in .142 and .143, but use your own real IPs here!

<VirtualHost *:80>
    <Proxy balancer://mycluster>
        # Web Server 1 (Replace with your server's IP)
        BalancerMember http://192.168.137.142:80

        # Web Server 2 (Replace with your server's IP)
        BalancerMember http://192.168.137.143:80

        ProxySet lbmethod=byrequests
    </Proxy>

    # Forward all incoming traffic to the balanced cluster
    ProxyPass / balancer://mycluster/
    ProxyPassReverse / balancer://mycluster/

</VirtualHost>

What this configuration does:

  1. It defines a proxy group named mycluster.
  2. It lists both Web Server 1 and Web Server 2 as BalancerMembers within that cluster.
  3. lbmethod=byrequests ensures the load is balanced sequentially (round-robin).
  4. ProxyPass directs all root directory traffic (/) to our new balanced cluster.

Save and close the file (Escape, then :wq!).

Restart Apache

For the changes to take effect, we must restart the Apache service on the Load Balancer Server:

sudo service httpd restart

If the restart is successful, you are ready for the final test!

Testing the Load Balancer

First, you need the public IP address of your Load Balancer Server. On the Load Balancer, run:

ifconfig

Note down the IP address (e.g., 192.168.137.141).

Now, open your web browser and navigate to the IP address of the Load Balancer:

http://[Your Load Balancer IP]

When you hit Enter, you should see the message: “This is Server 2. Howdy!” (or Server 1, depending on which server handled the first request).

Here’s the fun part: Hit the refresh button repeatedly!

  • Refresh 1: “This is Server 2. Howdy!”
  • Refresh 2: “This is Server 1. Howdy!”
  • Refresh 3: “This is Server 2. Howdy!”
  • Refresh 4: “This is Server 1. Howdy!”

If the content alternates between Server 1 and Server 2 with every refresh, congratulations—your Apache Active-Active load balancer is configured and working perfectly!

Summary and Next Steps

You have now successfully set up a simple yet highly effective active-active load balancing system on CentOS 7 using Apache. This foundation is crucial for any production environment where stability and scalability are priorities.

Encountered any issues along the way? Drop a comment below! I’m always happy to help troubleshoot your setup.

If you enjoyed mastering this skill, make sure you like this post and subscribe to Darren’s Tech Tutorials for more clear, actionable guides! Thanks for following along!