Configuring load balancing between Apache HTTP Server and Tomcat/tc Server using mod_jk
search cancel

Configuring load balancing between Apache HTTP Server and Tomcat/tc Server using mod_jk

book

Article ID: 343225

calendar_today

Updated On:

Products

VMware Support Only for Apache HTTP Support Only for Apache Tomcat

Issue/Introduction

This article provides information on configuring the Apache HTTP Server and Tomcat/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.

Environment

Apache HTTP Server 2.0
Apache Tomcat 5.5

Resolution

To set up mod_jk load balancing with Apache HTTP and Tomcat/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=loadbalancer

    worker.tcruntime8280.port=8209
    worker.tcruntime8280.host=localhost
    worker.tcruntime8280.type=ajp13
    worker.tcruntime8280.lbfactor=1

    worker.tcruntime8380.port=8309
    worker.tcruntime8380.host=localhost
    worker.tcruntime8380.type=ajp13
    worker.tcruntime8380.lbfactor=1

    worker.loadbalancer.type=lb
    worker.loadbalancer.balanced_workers=tcruntime8280,tcruntime8380

    Where

    • 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 /TCSession loadbalancer
    JkMount /TCSession/* loadbalancer
    </IfModule>

  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">

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

    tcruntime8380 worker:
<Engine defaultHost="localhost" name="Catalina" jvmRoute="tcruntime8380">
[...]
</Engine>
<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, TCSession.war, from the 2010433 _TCSession.zip file attached to this article.
  2. Save TCSession.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/TCSession.
  4. During the first access of a session, you should see a display similar to:

    TOMCAT localhost: This is the session id 5B5CF832B4CB62BEEECDABC334043286.tcruntime8380
    This is a new session !

  5. During subsequent requests sent for the same session, you should see a display similar to:
TOMCAT localhost: This is the session id 5B5CF832B4CB62BEEECDABC334043286.tcruntime8380
This is an existing session
Session Value: This is in my session


Additional Information

For more information, see:
Note: The preceding links were correct as of March 13, 2012. If you find a link is broken, provide feedback and a VMware 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.



Pivotal Links

Pivotal tc Server Knowledge Base:
Configuring load balancing between Apache HTTP Server and Tomcat/tc Server using mod_proxy

Attachments

2010433 _TCSession.zip get_app