In addition to jfarcands blog about mod_jk and GlassFish I also wanted to try out mod_jk loadbalancing with GlassFish. Here is the cookbook on how to get a simple load balancing scenario set up:
Apache Tomcat Connectors link
Apache Tomcat 5.5.16 (needed for just one jar File)
Apache Commons Logging 1.0.4 link
Apache Commons Modeler 1.1 link
And of course you need at least two running installations of GlassFish V1/V2.
Install mod_jk into your Apache config (copy mod_jk.so to your Apache modules directory)
Steps to setup load balancing:
Configure your Apache httpd to include mod_jk.so by editing your httpd.conf to include the following:
Create a worker.properties File for the mod_jk connector. In the example shown below a load balancing worker for two local GlassFish instances (listening on jk port 8009/8010) is provided.
LoadModule jk_module modules/mod_jk.so
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
#Mount your webapps eg WebApplication1 using JkMount
JkMount /WebApplication1/\* loadbalancer
Enable the jk connector in each GlassFish instance by adding a JVM Option with asadmin. If your instances run on the same box you have to choose different JK ports. The ports must also match your worker.workerX.port definitions in your worker.properties files.
Copy the following jar archives to your GlassFish Installations lib directory ($GLASSFISH_HOME/lib): tomcat-ajp.jar (from Tomcat 5.5.16 /server/lib dir), commons-logging.jar and commons-modeler.jar.
Next restart your apache httpd and your glassfish instances.
If JK connector was enabled successfully in glassfish you should see a log entry in your server log as for example:
org.apache.jk.common.ChannelSocket|_ThreadID=11;_ThreadName=Thread-5;|JK: ajp13 listening on /0.0.0.0:8009|#]
Now all web applications that are deployed to your GlassFish instances and that are mounted in your httpd.conf through JkMount commands should be loadbalanced equally.
More advanced jk configuration properties may be found in the Tomcat connectors documentation