Pivotal Knowledge Base

Follow

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

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

Purpose

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

Resolution

To set up mod_proxy load balancing with Apache HTTP Server and Tomcat/tc Server, the Apache httpd and Tomcat tc Server configuration must be modified. The HTTP(S), AJP, and FTP protocols can be used with mod_proxy load balancing. To use HTTP(S), AJP, and FTP protocols with mod_proxy load balancing, you need these Apache httpd load modules:
  • mod_proxy
  • mod_proxy_balancer
  • One or more mod_proxy_http,
  • mod_proxy_ajp
  • mod_proxy_ftp
To configure load balancing between Apache HTTP and Tomcat/tc Server using mod_proxy:
  1. In the Apache httpd conf/httpd.conf or conf/httpsd.conf, load and configure the mod_proxy modules.  A sample configuration appears similar to:

    LoadModule proxy_module "/install-path/apache2.2/modules/standard/mod_proxy.so"
    LoadModule proxy_http_module "/install-path/apache2.2/modules/standard/mod_proxy_http.so"
    LoadModule proxy_balancer_module "/install-path/apache2.2/modules/standard/mod_proxy_balancer.so"
    <IfModule mod_proxy_balancer.c>
        ProxyPass /TCSession balancer://mycluster/TCSession stickysession=JSESSIONID|jsessionid
        <Proxy balancer://mycluster>
            BalancerMember http://localhost:8280 route=tcruntime8280
            BalancerMember http://localhost:8380 route=tcruntime8380
        </Proxy>
    </IfModule>

  2. In the Tomcat/tc Server instance(s) server.xml file, ensure that an HTTP connector is created with the port matching the value entered for the BalancerMembers. 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 BalanceMembers shown in the preceding sample configuration file, you see:

    tcruntime8280 worker:

    <Engine defaultHost="localhost" name="Catalina" jvmRoute="tcruntime8280">
            [...]
    </Engine>
    <Connector port="8280" protocol="org.apache.coyote.http11.Http11Protocol" ... />

    tcruntime8380 worker"

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

            [...]
    </Engine>
    <Connector port="8380" protocol="org.apache.coyote.http11.Http11Protocol" ... />
To verify if the configuration is set correctly and the sticky sessions are working:
  1. Extract the sample Web application, TCSession.war, from the 2010450_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 September 7, 2014. If you find a link is broken, provide feedback and a Pivotal employee will update the link.
  • If you see the 404 Not Found error for the Apache httpd load balancer, ensure that the mod_proxy_balancer load module is being loaded into the Apache httpd configuration.
  • 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 route property of the BalanceMember in the Apache httpd configuration.

See Also

Attachments

 
©Pivotal 2013

Comments

Powered by Zendesk