Application server load balancing using Apache JServ Protocol

Apache JServ Protocol (AJP) is a binary protocol which is mainly used as an inbound web request load balancer from a web server through to an several application servers. Inbound web requests (Sessions) are redirected to correct application server using a context based routing mechanism.

 

In this example, we are focusing on Apache 2.2 which uses proxy ajp, proxy and proxy balancer as the web server while Apache Tomcat 6.0.20 and Jboss 5.1.0.GA as the application servers.First, let’s configure AJP on Apache Tomcat.

 

By default AJP 1.3 is configured in Apache tomcat and default port is 8009. You may have to change this port accordingly to eliminate port conflict with any other application servers running on the server. Let’s consider port 8011 is available and configuration will be,

 

(apache-tomcat-6.0.20/conf/server.xml)

<Connector port=”8011″ protocol=”AJP/1.3″ redirectPort=”8443″ />

Now lets configure AJP on Jboss. As with Apache Tomcat, Jboss 5.1.0.GA too comes with AJP enabled on port 8009. Let’s consider port 8012 is available and configuration will be,

(jboss-5.1.0.GA/server/default/deploy/jbossweb.sar/server.xml)

<Connector protocol=”AJP/1.3″ port=”8012″ address=”${jboss.bind.address}” redirectPort=”8443″ />

After above changes, both services needs to be restarted for changes to take effect. Now let’s configure AJP on the Apache 2.2 web server. To enable AJP on Apache 2.2 run the following command.

sudo a2enmod proxy
sudo a2enmod proxy_ajp

Now let’s create AJP configuration file.Let’s consider applications Crystal and Diamond are deplyed in Apache Tomcat and Jboss respectively. AJP config file will be,

(/etc/apache2/ajp.conf)

ProxyPass /Crystal ajp://localhost:8011/Crystal
ProxyPassReverse /Crystal ajp://localhost:8011/Crystal

ProxyPass /Diamond ajp://localhost:8012/Diamond
ProxyPassReverse /Diamond ajp://localhost:8012/Diamond

There after include the AJP config file to apache configuration file as follows.

(/etc/apache2/apache2.conf)

# Include tomcat ajp settings
Include /etc/apache2/ajp.conf

After above changes, reload the apache2 service.

sudo /etc/init.d/apache2 reload

2 thoughts on “Application server load balancing using Apache JServ Protocol

Leave a Reply

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