Load Balancing your JBoss App Servers with Apache

If you have your web application deployed on an application server and you need it to be online with a good uptime you should know that applications servers are not always very reliable. That's why it is a good idea to run two or more application servers and load balance them so that you can share the load, thereby reducing the dependence on one server and also handling the load better.

A single instance of the Apache web server can handle a large number of simple requests for files to be served quite well. However, a single instance of an application server such as JBoss can handle far fewer requests for applications to be run. There's a big difference between just handing someone a piece of data and having to work out something complicated to answer a question. So we'll use the Apache web server as a load balancer between two instances of JBoss, running the same application.

I'll assume that you have three servers; real server or virtual servers are fine. You will need to run your JBoss instances on two of these servers. You can alternatively run both instances of JBoss on the same server. However, make sure that they are both operating on different ports and not the same one. The default port on which JBoss run is 8080. Once both of your instances are up and running run a simple test to make sure things are running fine on both server. Launch your web browser and go to http://host:8080. I'll assume that the IP addresses of the two JBoss servers are and

Now we'll setup Apache. You can use the standard installation of Apache that shipped with your Linux distribution, or install it using a standard binary. We will be using a specific Apache module, mod_jk, to do the load balancing. This module does not usually ship with a copy of Apache and would need to be downloaded and setup separately. Installing mod_jk is pretty straightforward:

1. Download the module from

2. Copy the .so file into /usr/lib/apache2/modules/ This location may differ from distribution to distribution.
3. Now execute the following "# echo LoadModule jk_module /usr/lib/apache2/modules/" > /etc/apache2/mods-available/jk.load".
4. And "# touch /etc/apache2/mods-available/jk.conf".
5. And "# touch /etc/apache2/workers.conf".
6. "# a2enmod jk".
There you go. mod_jk should now be all setup. Just make sure you don't receive any errors while executing any of the steps shown above. I'll assume you have the web server running on so our setup looks something like the following:

Apache Web Server: - lb1
JBoss App Server 1: - app1
JBoss App Server 2: - app2
Next create the file /etc/apache2/workers.conf in the lb1 machine. Enter the following content into it:

# Defining the workers list:
# first worker properties, we use the AJB13 connection type:
# second worker properties, we use the AJB13 connection type:
# No we set the load balancing config
Replace 'app1' and 'app2' with the names of your app server machines. Next up edit or create the file '/etc/apache2/mods-available/jk.conf' to look like this:

<IfModule mod_jk.c>
# The Jk shared mem location
JkShmFile /var/log/apache2/mod_jk.shm

# Jk logs
JkLogFile /var/log/apache2/mod_jk.log
# Jk loglevel
JkLogLevel info
# Jk logformat
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

# Our workers config
JkWorkersFile /etc/apache2/workers.conf

# The most important:
# We will send eveything (/*) to our loadbalancer (set in JkWorkersFile)
JkMount /* loadbalancer
Restart your Apache web server with the command "# service httpd restart" or whatever works for your distribution. Now if you hit "" or lb1 in your web browser you should be able to see the results from one or the other app server. You should put in unique pages on each server to make sure it is the case. We have chosen two app servers in this case. However, this is not a limitation. You can choose to have more servers if you like.

Sukrit Dhandhania wrote this article for TechSource


  1. You should take a look at for doing more intelligent load balancing.

  2. Samuel MendenhallMarch 24, 2011

    You are missing some key properties like ping_mode=A. Generate an optimized config here:

  3. Using the HTTP connector (on JBoss) to listen to AJP/1.3 requests will not work. You need to first enable an AJP/1.3 connector on JBoss using a different port than 8080 and configure the to use the new port. See the links below as a reference. Other than this, nice article.