Configure Apache HTTP Server clustering with mod_cluster and JBoss EAP for enterprise load balancing

Advanced 45 min Apr 17, 2026 23 views
Ubuntu 24.04 Ubuntu 22.04 Debian 12 AlmaLinux 9 Rocky Linux 9 Fedora 41

Set up Apache HTTP Server with mod_cluster module to create an intelligent load balancing cluster with JBoss EAP application servers, featuring automatic node discovery, session clustering, and health monitoring.

Prerequisites

  • Root or sudo access
  • At least 4GB RAM
  • Java 11 or higher
  • Basic understanding of enterprise Java applications
  • Network connectivity between cluster nodes

What this solves

This tutorial shows how to configure Apache HTTP Server with the mod_cluster module to create an intelligent load balancing solution for JBoss EAP application servers. Unlike traditional load balancers, mod_cluster provides dynamic configuration, automatic node discovery, and context-aware routing based on real-time server metrics.

You'll learn to set up a complete clustering environment with session replication, automatic failover, and comprehensive health monitoring for enterprise Java applications.

Step-by-step installation

Update system packages

Start by updating your system to ensure you have the latest packages and security updates.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Install Apache HTTP Server and development tools

Install Apache web server along with development tools needed for compiling mod_cluster from source.

sudo apt install -y apache2 apache2-dev gcc make curl wget unzip
sudo a2enmod ssl
sudo a2enmod headers
sudo a2enmod rewrite
sudo dnf install -y httpd httpd-devel gcc make curl wget unzip
sudo systemctl enable httpd

Download and compile mod_cluster

Download the latest mod_cluster source code and compile it for your Apache installation.

cd /tmp
wget https://github.com/modcluster/mod_cluster/releases/download/2.0.6.Final/mod_cluster-2.0.6.Final-linux-x86_64-ssl.tar.gz
tar -xzf mod_cluster-2.0.6.Final-linux-x86_64-ssl.tar.gz
cd mod_cluster-2.0.6.Final

Install mod_cluster modules

Copy the compiled mod_cluster modules to Apache's modules directory and set proper permissions.

sudo cp so/mod_proxy_cluster.so /usr/lib/apache2/modules/
sudo cp so/mod_cluster_slotmem.so /usr/lib/apache2/modules/
sudo cp so/mod_manager.so /usr/lib/apache2/modules/
sudo cp so/mod_advertise.so /usr/lib/apache2/modules/
sudo chown root:root /usr/lib/apache2/modules/mod_*.so
sudo chmod 644 /usr/lib/apache2/modules/mod_*.so
sudo cp so/mod_proxy_cluster.so /usr/lib64/httpd/modules/
sudo cp so/mod_cluster_slotmem.so /usr/lib64/httpd/modules/
sudo cp so/mod_manager.so /usr/lib64/httpd/modules/
sudo cp so/mod_advertise.so /usr/lib64/httpd/modules/
sudo chown root:root /usr/lib64/httpd/modules/mod_*.so
sudo chmod 644 /usr/lib64/httpd/modules/mod_*.so

Configure mod_cluster in Apache

Create the mod_cluster configuration file to define cluster behavior and load balancing parameters.

LoadModule cluster_slotmem_module modules/mod_cluster_slotmem.so
LoadModule manager_module modules/mod_manager.so
LoadModule proxy_cluster_module modules/mod_proxy_cluster.so
LoadModule advertise_module modules/mod_advertise.so
sudo a2enmod cluster
LoadModule cluster_slotmem_module modules/mod_cluster_slotmem.so
LoadModule manager_module modules/mod_manager.so
LoadModule proxy_cluster_module modules/mod_proxy_cluster.so
LoadModule advertise_module modules/mod_advertise.so

Create mod_cluster virtual host configuration

Configure a dedicated virtual host for mod_cluster management and load balancing operations.


    ServerName cluster-manager.example.com
    
    # Enable mod_cluster manager
    
        SetHandler mod_cluster-manager
        Require ip 127.0.0.1
        Require ip 10.0.0.0/24
    
    
    # Configure mod_cluster parameters
    CreateBalancers 1
    ProxyPreserveHost On
    ManagerBalancerName mycluster
    
    # Health checking
    PingMode 1
    PingTimeout 10
    
    # Session stickiness
    UseAlias 1
    
    # Advertising configuration
    ServerAdvertise On
    AdvertiseFrequency 5
    AdvertiseBindAddress 224.0.1.105:23364
    
    # Allow connections from JBoss nodes
    
        Require ip 127.0.0.1
        Require ip 10.0.0.0/24
    
    
    # Error and access logs
    ErrorLog ${APACHE_LOG_DIR}/mod_cluster_error.log
    CustomLog ${APACHE_LOG_DIR}/mod_cluster_access.log combined
sudo a2ensite mod-cluster
sudo a2dissite 000-default

    ServerName cluster-manager.example.com
    
    # Enable mod_cluster manager
    
        SetHandler mod_cluster-manager
        Require ip 127.0.0.1
        Require ip 10.0.0.0/24
    
    
    # Configure mod_cluster parameters
    CreateBalancers 1
    ProxyPreserveHost On
    ManagerBalancerName mycluster
    
    # Health checking
    PingMode 1
    PingTimeout 10
    
    # Session stickiness
    UseAlias 1
    
    # Advertising configuration
    ServerAdvertise On
    AdvertiseFrequency 5
    AdvertiseBindAddress 224.0.1.105:23364
    
    # Allow connections from JBoss nodes
    
        Require ip 127.0.0.1
        Require ip 10.0.0.0/24
    
    
    # Error and access logs
    ErrorLog /var/log/httpd/mod_cluster_error.log
    CustomLog /var/log/httpd/mod_cluster_access.log combined

Install JBoss EAP

Download and install JBoss EAP application server which will serve as cluster nodes.

cd /opt
sudo wget https://developers.redhat.com/download-manager/file/jboss-eap-8.0.0.zip
sudo unzip jboss-eap-8.0.0.zip
sudo mv jboss-eap-8.0 jboss-eap
sudo chown -R jboss:jboss /opt/jboss-eap

Create JBoss user and group

Create a dedicated system user for running JBoss EAP securely without root privileges.

sudo groupadd -r jboss
sudo useradd -r -g jboss -d /opt/jboss-eap -s /bin/bash jboss
sudo chown -R jboss:jboss /opt/jboss-eap

Configure JBoss EAP for clustering

Create a clustered configuration for JBoss EAP with mod_cluster connector enabled.



    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
    
    
        
    
    
    
        
            
                
                    
                    
                
                
                    
                
            
        
        
            
                
            
            
                
            
            
                
                    
                
            
        
        
            
                
                
            
        
        
            
                
                    
                        
                    
                
            
        
    
    
    
        
            
                
                
                    
                
            
            
                
                    
                
                
                
                
            
            
                
            
            
                
            
            
                
            
            
                
            
            
                
                
                    
                    
                
            
            
                
            
            
                
            
        
        
        
            
                
                    
                
            
        
        
        
            
                
                
            
            
                
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                
                
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                
            
        
        
        
            
                
            
            
        
        
        
            
                
                
                    
                    
                
                
                    
                    
                
            
            
                
                
                    
                    
                
            
            
                
                
                    
                    
                
                
                    
                    
                    
                
                
            
        
        
        
            
            
                
                
                
                
                    
                    
                
            
            
                
                
            
            
                
            
        
    
    
    
        
            
        
        
            
        
    
    
    
        
        
        
        
        
        
        
        
        
        
        
    

Create systemd service for JBoss EAP cluster nodes

Create systemd service files for running multiple JBoss EAP instances as cluster nodes.

[Unit]
Description=JBoss EAP Node 1
After=network.target

[Service]
Type=simple
User=jboss
Group=jboss
ExecStart=/opt/jboss-eap/bin/standalone.sh -c standalone-ha-mod-cluster.xml -Djboss.bind.address=0.0.0.0 -Djboss.bind.address.management=0.0.0.0 -Djboss.node.name=node1 -Djboss.socket.binding.port-offset=0
ExecStop=/bin/kill -TERM $MAINPID
Restart=always
RestartSec=10
Environment=JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
Environment=JBOSS_HOME=/opt/jboss-eap
WorkingDirectory=/opt/jboss-eap

[Install]
WantedBy=multi-user.target
[Unit]
Description=JBoss EAP Node 2
After=network.target

[Service]
Type=simple
User=jboss
Group=jboss
ExecStart=/opt/jboss-eap/bin/standalone.sh -c standalone-ha-mod-cluster.xml -Djboss.bind.address=0.0.0.0 -Djboss.bind.address.management=0.0.0.0 -Djboss.node.name=node2 -Djboss.socket.binding.port-offset=100
ExecStop=/bin/kill -TERM $MAINPID
Restart=always
RestartSec=10
Environment=JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
Environment=JBOSS_HOME=/opt/jboss-eap
WorkingDirectory=/opt/jboss-eap

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload

Install Java Development Kit

Install OpenJDK which is required for running JBoss EAP application server.

sudo apt install -y openjdk-11-jdk
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
echo 'export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64' | sudo tee -a /etc/environment
sudo dnf install -y java-11-openjdk-devel
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
echo 'export JAVA_HOME=/usr/lib/jvm/java-11-openjdk' | sudo tee -a /etc/environment

Configure firewall rules

Open necessary ports for cluster communication, web traffic, and management interfaces.

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 8080/tcp
sudo ufw allow 8180/tcp
sudo ufw allow 8009/tcp
sudo ufw allow 8109/tcp
sudo ufw allow 9990/tcp
sudo ufw allow 10090/tcp
sudo ufw allow 7600/tcp
sudo ufw allow 7700/tcp
sudo ufw allow 55200/udp
sudo ufw allow 55300/udp
sudo ufw allow 45688/udp
sudo ufw allow 45788/udp
sudo ufw allow 23364/udp
sudo ufw --force enable
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --permanent --add-port=443/tcp
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --permanent --add-port=8180/tcp
sudo firewall-cmd --permanent --add-port=8009/tcp
sudo firewall-cmd --permanent --add-port=8109/tcp
sudo firewall-cmd --permanent --add-port=9990/tcp
sudo firewall-cmd --permanent --add-port=10090/tcp
sudo firewall-cmd --permanent --add-port=7600/tcp
sudo firewall-cmd --permanent --add-port=7700/tcp
sudo firewall-cmd --permanent --add-port=55200/udp
sudo firewall-cmd --permanent --add-port=55300/udp
sudo firewall-cmd --permanent --add-port=45688/udp
sudo firewall-cmd --permanent --add-port=45788/udp
sudo firewall-cmd --permanent --add-port=23364/udp
sudo firewall-cmd --reload

Start all services

Enable and start Apache HTTP Server and both JBoss EAP cluster nodes.

sudo systemctl enable apache2
sudo systemctl start apache2
sudo systemctl enable jboss-node1
sudo systemctl start jboss-node1
sudo systemctl enable jboss-node2
sudo systemctl start jboss-node2
sudo systemctl enable httpd
sudo systemctl start httpd
sudo systemctl enable jboss-node1
sudo systemctl start jboss-node1
sudo systemctl enable jboss-node2
sudo systemctl start jboss-node2

Create a sample clustered application

Deploy a simple web application that demonstrates session clustering and failover capabilities.



    
    Cluster Test Application
    
    
    
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.Date" %>
<%@ page import="java.net.InetAddress" %>



    Cluster Test Application
    


    

JBoss EAP Cluster Test

Server Information

Server: <%= InetAddress.getLocalHost().getHostName() %>
Node Name: <%= System.getProperty("jboss.node.name") %>
Current Time: <%= new Date() %>
Session ID: <%= session.getId() %>
<% String visitCount = (String) session.getAttribute("visitCount"); if (visitCount == null) { visitCount = "1"; } else { visitCount = String.valueOf(Integer.parseInt(visitCount) + 1); } session.setAttribute("visitCount", visitCount); session.setAttribute("lastVisit", new Date().toString()); %>

Session Information

Visit Count: <%= visitCount %>
Last Visit: <%= session.getAttribute("lastVisit") %>
Session Created: <%= new Date(session.getCreationTime()) %>
Max Inactive Interval: <%= session.getMaxInactiveInterval() %> seconds
Refresh Page Invalidate Session
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>



    Session Invalidated
    


    

Session Invalidated

<% session.invalidate(); %>

Your session has been invalidated. Click the link below to start a new session.

Start New Session
sudo mkdir -p /opt/jboss-eap/standalone/deployments/cluster-test.war/WEB-INF
sudo chown -R jboss:jboss /opt/jboss-eap/standalone/deployments/cluster-test.war

Configure session clustering and failover

Enable session replication

Configure both JBoss nodes to replicate session data for seamless failover between cluster nodes.



    
    
        SESSION
        SET_AND_NON_PRIMITIVE_GET
    
    

Configure health monitoring

Set up comprehensive health checks and monitoring for the cluster nodes and load balancer.

<%@ page language="java" contentType="text/plain; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="javax.naming.*" %>
<%
    response.setContentType("text/plain");
    
    try {
        // Basic health check
        String nodeName = System.getProperty("jboss.node.name", "unknown");
        long freeMemory = Runtime.getRuntime().freeMemory();
        long totalMemory = Runtime.getRuntime().totalMemory();
        long usedMemory = totalMemory - freeMemory;
        double memoryUsage = (double) usedMemory / totalMemory * 100;
        
        if (memoryUsage < 90) {
            response.setStatus(200);
            out.println("OK - Node: " + nodeName + ", Memory Usage: " + String.format("%.2f", memoryUsage) + "%");
        } else {
            response.setStatus(503);
            out.println("ERROR - High memory usage: " + String.format("%.2f", memoryUsage) + "%");
        }
    } catch (Exception e) {
        response.setStatus(503);
        out.println("ERROR - " + e.getMessage());
    }
%>

Configure automatic node discovery

Enable multicast advertising

Configure automatic node discovery using multicast advertising so new nodes automatically join the cluster.

# Enable IP forwarding for multicast
net.ipv4.ip_forward = 1

Increase multicast buffer sizes

net.core.rmem_default = 262144 net.core.rmem_max = 16777216 net.core.wmem_default = 262144 net.core.wmem_max = 16777216

Allow multicast

net.ipv4.conf.all.mc_forwarding = 1
sudo sysctl -p /etc/sysctl.d/99-multicast.conf

Restart services and test discovery

Restart all services to apply configuration changes and verify automatic node discovery is working.

sudo systemctl restart apache2
sudo systemctl restart jboss-node1
sudo systemctl restart jboss-node2
sudo systemctl restart httpd
sudo systemctl restart jboss-node1
sudo systemctl restart jboss-node2

Performance optimization and monitoring

Optimize Apache for clustering

Configure Apache performance settings specifically optimized for cluster traffic and high availability.

# Add these lines to optimize for clustering

Increase worker limits for cluster traffic

ServerLimit 16 MaxRequestWorkers 400 ThreadsPerChild 25

Connection pooling for backend servers

ProxyIOBufferSize 65536 ProxyReceiveBufferSize 262144

Enable persistent connections

ProxyPreserveHost On ProxyAddHeaders On

Timeout settings for cluster health

ProxyTimeout 30 ProxyConnectTimeout 5

Enable status monitoring

ExtendedStatus On
# Add these lines to optimize for clustering

Increase worker limits for cluster traffic

ServerLimit 16 MaxRequestWorkers 400 ThreadsPerChild 25

Connection pooling for backend servers

ProxyIOBufferSize 65536 ProxyReceiveBufferSize 262144

Enable persistent connections

ProxyPreserveHost On ProxyAddHeaders On

Timeout settings for cluster health

ProxyTimeout 30 ProxyConnectTimeout 5

Enable status monitoring

ExtendedStatus On

Configure monitoring endpoints

Set up monitoring endpoints to track cluster health, performance metrics, and node status.


    ServerName monitoring.example.com
    
    # Apache server status
    
        SetHandler server-status
        Require ip 127.0.0.1
        Require ip 10.0.0.0/24
    
    
    # Apache server info
    
        SetHandler server-info
        Require ip 127.0.0.1
        Require ip 10.0.0.0/24
    
    
    # Mod_cluster status
    
        ProxyPass http://localhost/mod_cluster_manager
        ProxyPassReverse http://localhost/mod_cluster_manager
        Require ip 127.0.0.1
        Require ip 10.0.0.0/24
    
    
    ErrorLog ${APACHE_LOG_DIR}/monitoring_error.log
    CustomLog ${APACHE_LOG_DIR}/monitoring_access.log combined


Listen on port 8081 for monitoring

Listen 8081
sudo a2ensite monitoring
sudo a2enmod status
sudo a2enmod info

    ServerName monitoring.example.com
    
    # Apache server status
    
        SetHandler server-status
        Require ip 127.0.0.1
        Require ip 10.0.0.0/24
    
    
    # Apache server info
    
        SetHandler server-info
        Require ip 127.0.0.1
        Require ip 10.0.0.0/24
    
    
    # Mod_cluster status
    
        ProxyPass http://localhost/mod_cluster_manager
        ProxyPassReverse http://localhost/mod_cluster_manager
        Require ip 127.0.0.1
        Require ip 10.0.0.0/24
    
    
    ErrorLog /var/log/httpd/monitoring_error.log
    CustomLog /var/log/httpd/monitoring_access.log combined


Listen on port 8081 for monitoring

Listen 8081

Final service restart

Restart Apache to apply all configuration changes and complete the cluster setup.

sudo systemctl reload apache2
sudo systemctl reload httpd

Verify your setup

# Check Apache status
sudo systemctl status apache2  # or httpd on RHEL-based systems

Check JBoss cluster nodes

sudo systemctl status jboss-node1 sudo systemctl status jboss-node2

Test mod_cluster manager interface

curl -s http://localhost/mod_cluster_manager

Test cluster application

curl -s http://localhost:8080/cluster-test/ | grep "Visit Count"

Check cluster node registration

curl -s http://localhost/mod_cluster_manager | grep -A 5 "Balancer"

Test session stickiness

curl -c cookies.txt -b cookies.txt http://localhost:8080/cluster-test/ curl -c cookies.txt -b cookies.txt http://localhost:8080/cluster-test/

Check health endpoints

curl -s http://localhost:8080/cluster-test/health.jsp curl -s http://localhost:8180/cluster-test/health.jsp

Monitor Apache server status

curl -s http://localhost:8081/server-status?auto

Check cluster member discovery

grep -i "cluster" /opt/jboss-eap/standalone/log/server.log | tail -10
Note: The cluster may take 30-60 seconds to fully initialize after starting services. Node discovery and registration with mod_cluster happens automatically via multicast advertising.

Testing session failover

To test session clustering and failover capabilities, you can simulate node failures and verify that sessions are preserved across cluster nodes. This is essential for ensuring high availability in production environments.

# Start a session on node 1
curl -c session.txt http://localhost:8080/cluster-test/

Stop node 1 to simulate failure

sudo systemctl stop jboss-node1

Continue session on node 2 (should preserve session data)

curl -b session.txt http://localhost:8080/cluster-test/

Restart node 1

sudo systemctl start jboss-node1

Verify node rejoins cluster

curl -s http://localhost/mod_cluster_manager | grep node1

Load balancing verification

Test that mod_cluster properly distributes requests across available nodes based on server metrics and health status.

# Create test script for load distribution
cat > test_load_balancing.sh << 'EOF'
#!/bin/bash

echo "Testing load distribution across cluster nodes..."

for i in {1..20}; do
    response=$(curl -s http://localhost:8080/cluster-test/ | grep "Node Name")
    echo "Request $i: $response"
    sleep 1
done
EOF

chmod +x test_load_balancing.sh
./test_load_balancing.sh

Common issues

SymptomCauseFix
Nodes not registering with mod_clusterMulticast not working or firewall blockingCheck sudo netstat -tulpn | grep 23364 and verify firewall rules
Session data not replicatingMissing <distributable/> in web.xmlAdd distributable element to web application descriptor
High memory usage on cluster nodesSession replication overheadTune JVM heap size: -Xmx2g -Xms1g in service file
Load balancer not detecting failed nodesHealth check timeout too longReduce PingTimeout in mod_cluster configuration
Apache returns 503 Service UnavailableNo healthy backend nodes availableCheck JBoss logs: tail -f /opt/jboss-eap/standalone/log/server.log
Cluster nodes can't communicateJGroups configuration issuesVerify multicast connectivity: sudo tcpdump -i any host 230.0.0.4
Security Warning: Never use the management interfaces in production without proper authentication. The configurations shown here are for development and testing only. Always implement SSL/TLS, strong authentication, and network access controls for production deployments.

Next steps

Running this in production?

Want this handled for you? Running enterprise Java clustering at scale adds a second layer of work: capacity planning, security hardening, backup strategies, and 24/7 monitoring. See how we run infrastructure like this for European SaaS and enterprise teams.

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed cloud infrastructure for businesses that depend on uptime. From initial setup to ongoing operations.