- Create or modify the Apache httpd conf/workers.properties file to define the workers to which the requests are to be load balanced, along with their associated ports and hosts. For example, if there are two Tomcat/tc Server workers running on the localhost listening on AJP ports 8209 and 8309, the workers.properties file appears similar to:
- worker.list lists the workers visible external to mod_jk. In this case, only the loadbalancer worker is used in the Apache httpd.conf/ httpsd.conf file.
- worker.tcruntime8380 and worker.tcruntime8380 properties identify two Tomcat/tcServer instances to receive requests forwarded from Apache using mod_jk loadbalancing.
- worker.loadbalancer properties define the worker loadbalancer to be a load balancing (lb) worker and that its set of worker servers consists of internal workers tcruntime8380 and tcruntime8380 .
- In the Apache HTTP Server's conf/httpd.conf or conf/httpsd.conf file, load and configure the mod_jk module. A sample configuration appears similar to:
LoadModule jk_module "/home/ers403/apache2.2/modules/jakarta/mod_jk.so"
JkMount /TCSessionRepl loadbalancer
JkMount /TCSessionRepl/* loadbalancer
- In the Tomcat/tc Server instance(s) server.xml file, ensure that an AJP connector is created with the port matching the value entered in the workers.properties file. For sticky sessions, also ensure that a jvmRoute matching the worker name used in the workers.properties file is set. For example, for the two workers shown in the preceding workers.properties file, you see:
<Engine defaultHost="localhost" name="Catalina" jvmRoute="tcruntime8280">
<Connector port="8209" protocol="AJP/1.3" ... />
<Connector port="8309" protocol="AJP/1.3" ... />
To verify if the configuration is set correctly and the sticky sessions are working:
- Extract the sample Web application, TCSessionRepl.war, from the 20151030 _TCSessionRepl.zip file attached to this article.
- Save TCSessionRepl.war to each Tomcat/tc Server instance's webapps directory, so that it is deployed.
- Access the Web application via Apache HTTP server with a UR, such as http://localhost/TCSessionRepl.
- During the first access of a session, you should see a display similar to:
Current count is 0
- During subsequent requests sent for the same session, you should see a display similar to:
Current count is 1
- Ensure that the hostname/IP address and port are correct for the Tomcat/tc Server instances.
- Ensure that the Tomcat/tc Server instances are up, running, and listening.
- Ensure that there is no firewall blocking access to the host/port.
If load balancing appears to be working, but sticky sessions are not honored, ensure that the name provided in the Tomcat/tc Server configuration for the jvmRoute matches the name that is set for the worker name in the Apache httpd mod_jk workers (workers.properties) file.
- Download file 20151030_TCSessionRepl.zip below.