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:
- 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 "/home/ers403/apache2.2/modules/standard/mod_proxy.so"
LoadModule proxy_http_module "/home/ers403/apache2.2/modules/standard/mod_proxy_http.so"
LoadModule proxy_balancer_module "/home/ers403/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>
- 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:
- Extract the sample Web application, TCSession.war, from the 2010450_TCSession.zip file attached to this article.
- Save TCSession.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/TCSession.
- 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 !
- 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