You can use Apache HTTP server with Apache Tomcat Connector (mod_jk) to distribute workload to several JBoss or Tomcat instances and give users transparent access to these through a single URL.
In the example I use Apache 2.2.10, mod_jk 1.2.30 and either two instances of Tomcat 6.0.26 or JBoss 4.2.2 with NJX 8.1.2 on a Windows XP machine.
Install Apache:
- Just unzip the downloaded archive.
Install mod_jk:
- Copy mod_jk-1.2.30-httpd-2.2.3.so into the Apache modules directory.
- Add a file mod-jk.conf into the Apache conf directory (example contents see below).
- Add a file workers.properties to the Apache conf directory (example contents see below).
- Reference the file mod-jk.conf in the Apache httpd.conf file with a line
Include conf/mod-jk.conf
Contents of file conf/mod-jk.conf:
(find detailed information on the parameters under The Apache Tomcat Connectors: mod_jk, ISAPI redirector, NSAPI redirector (1.2.48) - Documentation Overview)
# Load mod_jk module
LoadModule jk_module modules/mod_jk-1.2.30-httpd-2.2.3.so
# Where to find worker.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
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
#JkOptions indicate to send SSK KEY SIZE
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"
# Mount your applications
JkMount /* loadbalancer
# Add shared memory
JkShmFile logs/jk.shm
Contents of file workers.properties
(find detailed information on the parameters under The Apache Tomcat Connectors: mod_jk, ISAPI redirector, NSAPI redirector (1.2.48) - Documentation Overview):
# Define list of workers
worker.list=loadbalancer,status
# Define Node1
worker.node1.host=localhost
worker.node1.port=8109
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node1.connection_pool_size=10
# Define Node2
worker.node2.host=localhost
worker.node2.port=8209
worker.node2.type=ajp13
worker.node2.lbfactor=1
worker.node2.connection_pool_size=10
# Load balancing behaviour
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
Note:
- The ports specified in worker.node1.port and worker.node2.port are the AJP13 ports of your JBoss/Tomcat instances, not the HTTP ports.
- In JBoss the set of ports to be used is defined in conf/jboss-service.xml
- In Tomcat the ports are defined in conf/server.xml
- You must use sticky sessions. Due to its connection to a Natural server session, a session created on a given JBoss or Tomcat instance must not be transferred to a different instance.
Configure your JBoss worker instances:
In deploy\jboss-web.deployer\server.xml add the jvmRoute name to the Engine element (corresponding to the worker names you used in the file workers.properties), for instance:
<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1">
In deploy\jboss-web.deployer\META-INF\jboss-service.xml set the attribute UseJK to true:
<attribute name="UseJK">true</attribute>
Configure your Tomcat worker instances:
In conf\server.xml add the jvmRoute name to the Engine element (corresponding to the worker names you used in the file workers.properties), for instance:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="node1">
Configure Application Designer:
in cis/cisconfig/cisconfig.xml set the attribute createhttpsession to true:
cisconfig ... createhttpsession="true" ...
Now start the Apache HTTP server and the worker instances and access your application under the HTTP port of the Apache HTTP server.