Configuring mod_jk with WildFly/JBoss AS 7

This tutorial contains an excerpt of the upcoming WilfFly Book which shows how to create a load balancing configuration for WildFly 8 using the older Apache Tomcat mod_jk. Although the recommended load balancing solution for clustering JBoss AS7/Wildfly is mod_cluster you should include in your administrator’s skill also the earlier Apache Tomcat mod_jk connector in some scenarios. Configuring it requires just a couple of minutes so why not trying it ?  

As first step download the latest stable Apache mod_jk connectors from http://tomcat.apache.org/download-connectors.cgi
Once completed the download, move the connector to the modules folder of your Apache 2 distribution

cp mod_jk.so $APACHE_HOME/modules

Now create a file named for example mod-jk.conf in your Apache configuration folder. This file will contain the basic mod_jk configuration including the application we are going to route from Apache to WildFly/JBossAS 7

# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile conf/workers.properties
# Where to put jk logs
JkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info 
# Mount your applications
# Send everything for context /myapp to worker1 (ajp13)
JkMount /myapp/* loadbalancer
JkShmFile logs/jk.shm

Notice the difference with mod_cluster where by default all applications are already mounted.

The above file needs to be included in your httpd.conf configuration:

Include conf/mod-jk.conf

Now the configuration about workers which are the single servers where calls are routed. Create a file named workers.properties in your configuration foldetr:

worker.list=loadbalancer,status

# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=8009
worker.node1.host=localhost
worker.node1.type=ajp13
worker.node1.ping_mode=A
worker.node1.lbfactor=1 

# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8159
worker.node2.host=localhost
worker.node2.type=ajp13
worker.node2.ping_mode=A
worker.node2.lbfactor=1

# Load-balancing behavior
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=1

# Status worker for managing load balancer
worker.status.type=status

The above configuration can be used for example on a cluster of nodes running on localhost with a port offset of 150 for the second node (hint: you can use a Domain mode configuration with the ha/full-ha profile for quickly testing this example).

Done with mod_jk, now let’s move to WildFly configuration. In the new release of the application server the built-in Web server is not anymore a fork of Tomcat project but a brand new product named Undertow that is a flexible performant web server written in java, providing both blocking and non-blocking API€™s based on NIO.
So from the Admin Console expand the Web subsystem and select HTTP. From there you will see the list of listeners (HTTP,AJP,HTTPs) which are configured. Select the AJP tab and click on “Add“.
apache tomcat mod_jk jboss wildfly apache tomcat mod_jk jboss wildfly
In the next window enter the name for the AJP listener and the Socket Binding to be used, in our case “ajp“.

 

apache tomcat mod_jk jboss wildfly

Next, from the “Edit” link verify that this listener is enabled by checking the “Enabled” checkbox.

apache tomcat mod_jk jboss wildfly
If you have started the server in ha domain mode you should have now both AJP listeners running with the configured port-offset

netstat -an | find "8009"
 TCP 127.0.0.1:8009 0.0.0.0:0 LISTENING

netstat -an | find "8159"
 TCP 127.0.0.1:8159 0.0.0.0:0 LISTENING

Conclusion: the major limit of mod_jk is that you have a static configuration of your cluster and that you don’t have access to server side metrics such as JVM, CPU etc. On the other hand, this connector is quite stable and has been tested for years as front-end solution for your farm of JBoss servers. One more point to consider is that all the mod_cluster goodies could not be available for example if your subsystem does not support multicast- this could be the case of a JBoss farm running on Windows Vista/7 (By the way if somebody out there ever managed to run multicast stack on this platform please mail me a row, I’ve never been able to!). In such a scenario I guess it could be worth consider using mod_jk.

Found the article helpful? if so please follow us on Socials