Loadbalancing with mod_jk and GlassFish
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:
Software needed:
Steps to setup load balancing:
LoadModule jk_module modules/mod_jk.so
JkWorkersFile path_to_your_config/conf/workers.properties
JkLogFile path_to_your_log_dir/mod_jk.log
JkLogLevel info
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
worker.list=loadbalancer
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.lbfactor=1
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300
worker.worker2.type=ajp13
worker.worker2.host=localhost
worker.worker2.port=8010
worker.worker2.lbfactor=1
worker.worker2.socket_keepalive=1
worker.worker2.socket_timeout=300
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=worker1,worker2
$GLASSFISH_HOME/bin/asadmin create-jvm-options
-Dcom.sun.enterprise.web.connector.enableJK=8009
[#|2006-12-01T11:33:14.667+0100|INFO|sun-appserver-pe9.0|
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
