JBoss AS7 Loadbalancer with mod_jk

Recently I’ve set up a JBoss AS7 behind a mod_jk based loadbalancer. This is the easier approach than to use the mod_cluster module, since this module has – despite its benefits for autoconfiguration – some drawbacks. Especially if you want to link the Java web application to special location of your web server and have a lot of other content configured in the server. mod_cluster works better if the Apache HTTPD is only running as a loadbalancer to the JBoss AS servers and not doing other jobs.

I’m using the Centos 6.2 distribution, which has the required modules in the httpd package. I assume the httpd is already set up and running, and for this example we assume it is running as www.example.com. First you should check in the default configuration /etc/httpd/conf/httpd.conf the the modules proxy_ajp_module and proxy_balancer_module are enabled.

Now we edit the configuration in /etc/httpd/conf.d/proxy_ajp.conf:

<Proxy balancer://application>
BalancerMember ajp://node-01.example.com:8009/application route=node-01
BalancerMember ajp://node-02.example.com:8009/application route=node-02
ProxySet stickysession=JSESSIONID

ProxyPass /application balancer://application
ProxyPassReverse /application balancer://application

<Location /balancer-manager>
SetHandler balancer-manager

We want to set up a Java web application which is located at /application and is running on the JBoss AS servers node-01.example.com and node-02.example.com. The port for the AJP protocol is 8009 and since the web application has sessions we declare them to be sticky. This setup is quite standardized, here you see nothing special to JBoss AS7. The balancer manager page within the Apache HTTP needs to get an access restriction (Allow, Deny) which fits your needs.

In the JBoss AS7 Server we need to adapt the configuration – which is usually standalone.xml

<subsystem xmlns=”urn:jboss:domain:web:1.1″ default-virtual-server=”default-host” instance-id=”node-01″ native=”false”>
<connector name=”http” protocol=”HTTP/1.1″ scheme=”http” socket-binding=”http”/>
<connector name=”ajp” protocol=”AJP/1.3″ scheme=”http” socket-binding=”ajp”/>
<virtual-server name=”default-host” enable-welcome-root=”true”>
<alias name=”localhost”/>
<alias name=”www.example.com”/>

<socket-binding-group name=”standard-sockets” default-interface=”public”>

<socket-binding name=”ajp” port=”8009″/>


Make sure that the instance-id matches the name of the route you have defined in the Apache HTTPD. Also declare an alias for the virtual server which needs to match your website. The ajp port needs to match the declared port in balancer declaration. If you need to you can limit the access to the ajp port by a separate interface declaration.

If you now start the JBoss AS7 and Apache HTTPD server, you should see 2 nodes registered in the balancer (at http://www.example.com/balancer-manager). Your cluster is ready to serve.

Tagged : , , ,

Leave a Reply