Pivotal Knowledge Base


Configuring load balancing between Apache HTTP / Pivotal Web server and Tomcat/Pivotal tc Server using mod_jk (2010433)

Configuring load balancing between Apache HTTP / Pivotal Web Server and Tomcat/Pivotal tc Server using mod_jk (2010433)


This article provides information on configuring the Apache HTTP /Pivotal Web Server and Tomcat/Pivotal tc Server using mod_jk load balancing. It also provides information on using sticky sessions to send all requests associated with a particular session to the same Tomcat/tc Server worker.


To set up mod_jk load balancing with Apache HTTP and Tomcat/Pivotal tc Server:
  1. 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 .

  2. 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"
    <IfModule mod_jk.c>
    JkLogFile logs/mod_jk.log
    JkLogLevel debug
    JkShmFile logs/jk-runtime-status
    JkWorkersFile conf/workers.properties

    JkMount /TCSessionRepl loadbalancer
    JkMount /TCSessionRepl/* loadbalancer

  3. 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:

    tcruntime8280 worker:

    <Engine defaultHost="localhost" name="Catalina" jvmRoute="tcruntime8280">

    <Connector port="8209" protocol="AJP/1.3" ... />

    tcruntime8380 worker:
<Engine defaultHost="localhost" name="Catalina" jvmRoute="tcruntime8380">
<Connector port="8309" protocol="AJP/1.3" ... />

To verify if the configuration is set correctly and the sticky sessions are working: 
  1. Extract the sample Web application, TCSessionRepl.war, from the 20151030 _TCSessionRepl.zip file attached to this article.
  2. Save TCSessionRepl.war to each Tomcat/tc Server instance's webapps directory, so that it is deployed.
  3. Access the Web application via Apache HTTP server with a UR, such as http://localhost/TCSessionRepl.
  4. During the first access of a session, you should see a display similar to:

    Session [9F00F928A8D0FB77389787C93AE09923.tcruntime8380]

    Node-Host: localhost
    Node-Port: 8309
    Current count is 0

  5. During subsequent requests sent for the same session, you should see a display similar to:
Session [9F00F928A8D0FB77389787C93AE09923.tcruntime8380]

Node-Host: localhost
Node-Port: 8309
Current count is 1

Additional Information

For more information, see:
Note: The preceding links were correct as of September 7, 2014. If you find a link is broken, provide feedback and a Pivotal employee will update the link.
If you see the 503 Service Unavailable error for the Apache httpd load balancer:
  • 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.

See Also


  • Download file 20151030_TCSessionRepl.zip below.
©Pivotal 2013


Powered by Zendesk