Configuring Tomcat With Apache or IIS For Load Balancing

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9
At a glance
Powered by AI
The key takeaways are how to configure multiple Tomcat instances with a single Apache or IIS load balancer for large implementations of ServiceCenter or Service Manager.

To configure multiple Tomcat instances with a single load balancer, you modify the server.xml files of each Tomcat with unique port numbers and jvmRoute values and configure the load balancer properties file.

The steps to configure Apache HTTP as the load balancer are to modify the httpd.conf file and workers.properties file with the Tomcat settings.

Configuring Tomcat with Apache or IIS for load

balancing
How to configure the Web Application Server and the Web Servers

Introduction ......................................................................................................................................... 2
Prerequisites ........................................................................................................................................ 2
Configuring Tomcat ............................................................................................................................. 2
Configuring Apache ............................................................................................................................ 4
Configuring Microsoft Internet Information Server .................................................................................... 5
For more information ............................................................................................................................ 9
Introduction
For large implementation it is often required to set up multiple Web Application Servers with a single
Web Server that functions as a load balancer. This document describes how to set up multiple Tomcat
Web Application Servers with a single Apache Web Server as the load balancer.
This document outlines the steps needed to install and configure Apache HTTP and Microsoft IIS to
load balance multiple Tomcat instances on single or multiple servers. Also covered is the
configuration of multiple Apache Tomcat instances. This is applicable to ServiceCenter version 6.x
and all versions of Service Manager. This document does not take into account any configuration in
support of SSL sessions.

Prerequisites
This document is meant for ServiceCenter 6.x and higher and Service Manager, Tomcat 5.0, 5.5, 6.0,
Apache 2.0 or 2.2 and IIS 6.0. HP recommends configuring the Tomcat JVM heap at 1024MB,
minimum and maximum. The will allow a single Tomcat container to serve approximately 100
concurrent users.

Configuring Tomcat
This configuration will work on Tomcat 5.0, 5.5, 6.0 on any supported Operating System. Ensure to
use a version of Tomcat that is listed in the compatibility matrix for your version of ServiceCenter or
Service Manager. Examples in this document will be provided for both Windows and Unix.

For Windows, we recommend to download the ZIP file containing a complete Tomcat installation
structure. The installer package for Windows does not contain the same files as other platforms.
After uncompressing the Tomcat package, modify the /conf/server.xml file, and optionally, create the
Windows service. The configuration described in this document uses the first Tomcat as the anchor
for the Service Manager web tier, with all other Tomcats using the /tomcat/webapps of this anchor
and creating their own work copy. This eases maintenance and upgrade issues by having only one
sm.war file in the system.

Below is a sample of the changes needed in the server.xml file for the main / anchor Tomcat.
Note: Some lines are included to provide comparison and are not changed from the default.
For the chained Tomcats, some parameters must be incremented to provide unique values. These
values that need to be adjusted are
 Shutdown Server Port
 HTTP Connector port
 AJP Connector port
 jvmRoute
jvmRoute is case sensitive and must match the values provided in the workers.properties file.

Server.xml – Anchor Tomcat


<Server port="8005" shutdown="SHUTDOWN">
...
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->

2
<Connector port="8080" maxHttpHeaderSize="8192"
enableLookups="false" redirectPort="8443"
acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true"/>
...
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" maxThreads="900" minSpareThreads="75"
maxSpareThreads="225" enableLookups="false" redirectPort="8443"
protocol="AJP/1.3" />
...
<!-- Define the top level container in our container hierarchy -->
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
...
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
...
<Context path="/sm920" docBase="/sm920" crossContext="false" debug="0"
reloadable="false" />

Server.xml – Chained Tomcat


<Server port="9005" shutdown="SHUTDOWN">
...
<!-- Define a non-SSL HTTP/1.1 Connector on port 8180 -->
<Connector port="8180" maxHttpHeaderSize="8192"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true"/>
...
<!-- Define an AJP 1.3 Connector on port 9009 -->
<Connector port="9009" maxThreads="900" minSpareThreads="75"
maxSpareThreads="225" enableLookups="false" redirectPort="8443"
protocol="AJP/1.3" />
...
<!-- Define the top level container in our container hierarchy -->
<Engine name="Catalina" defaultHost="localhost" debug="0"
jvmRoute="tomcat2">
...
<!-- For Windows -->
<Host name="localhost" appBase="c:\tomcat1\webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

<!-- For Unix -->


<Host name="localhost" appBase="/tomcat1/webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
...
<!-- For Windows -->
<Context path="/sm920" docBase="c:\tomcat1\webapps\sm920"
crossContext="false" debug="0" reloadable="false" />

<!-- For Unix -->


<Context path="/sm920" docBase="/tomcat1/webapps/sm920"
crossContext="false" debug="0" reloadable="false" />

3
Once the files outlined above are modified, the ServiceCenter / Service Manager WAR file can be
deployed as documented in the Service Manager install guide.
Note: The WAR file only needs to be deployed in the anchor Tomcat’s /webapps directory. The
chained Tomcats will read that deployed war file and create their own local copy in
./work/Catalina/localhost.
The Service Manager web tier web.xml then needs to be configured and the anchor Tomcat restarted
first before starting any of the chained Tomcats. Once all chained Tomcats are started and the Web
Server is configured and pointing to the Tomcat systems, the system is ready for use.

Configuring Apache
For this configuration, Apache 2.0 or 2.2 can be used on any supported operating system. The
mod_jk.so must be in ./modules in the Apache install directory. Additional information on advanced
Apache with Tomcat options, such as options in the mod_jk.so, are available at
http://tomcat.apache.org/connectors-doc/.

After installing Apache, first create a workers.properties file in the ./conf directory as highlighted
below and modify the httpd.conf file that was created in ./conf in the Apache install directory. Below
is a sample of the changes needed in the httpd.conf file, followed by a sample workers.properties
which was configured for six Tomcat instances:

Httpd.conf
# WinNT MPM
# ThreadsPerChild: constant number of worker threads in the server
process
# MaxRequestsPerChild: maximum number of requests a server process
serves
<IfModule mpm_winnt.c>
ThreadLimit 9000
ThreadsPerChild 3000
MaxRequestsPerChild 0
</IfModule>

#
# Add to end of httpd.conf for easy location
#

LoadModule jk_module modules/mod_jk.so

JkMount /sm930 loadbalancer


JkMount /sm930/* loadbalancer
JkMount /sm930/servlet/* loadbalancer
JkMount /sm930/*.jsp loadbalancer
JkMount /sm930/*.do loadbalancer
JkMount /sm930/attachments/* loadbalancer
JkMount /sm930/cwc/nav.menu loadbalancer

JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info

4
Workers.properties
worker.list=loadbalancer

worker.tomcat1.port=8009
worker.tomcat1.host=webserver01
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1

worker.tomcat2.port=9009
worker.tomcat2.host=webserver02
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1

worker.tomcat3.port=10009
worker.tomcat3.host=webserver03
worker.tomcat3.type=ajp13
worker.tomcat3.lbfactor=1

worker.tomcat4.port=11009
worker.tomcat4.host=webserver04
worker.tomcat4.type=ajp13
worker.tomcat4.lbfactor=1

worker.tomcat5.port=12009
worker.tomcat5.host=webserver05
worker.tomcat5.type=ajp13
worker.tomcat5.lbfactor=1
worker.tomcat5.cachesize=100

worker.tomcat6.port=13009
worker.tomcat6.host=webserver06
worker.tomcat6.type=ajp13
worker.tomcat6.lbfactor=1
worker.tomcat6.cachesize=100

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=tomcat1, tomcat2, tomcat3, tomcat4,
tomcat5, tomcat6

Start the Apache HTTP Server – the configuration is complete and Apache will act as the load
balancer for the multiple tomcat instances that were configured previously.

Configuring Microsoft Internet Information Server


This configuration was tested with Microsoft IIS 5.0 or 6.0, but this document uses examples provided
for IIS 6.0. Ensure that isapi_redirect.dll is placed in the ./bin directory within the Tomcat install
directory. The Apache Tomcat ISAPI redirector and additional information on IIS with Tomcat options
are available at http://tomcat.apache.org/connectors-doc/webserver_howto/iis.html. The files downloaded
from there will have the version number as part of the file name. Remove that version information from
the filename and save it as isapi_redirect.dll.

After downloading the ISAPI redirector, create the Isapi_redirect.properties file in the ./bin folder of
the Tomcat install directory. Create the workers.properties and uriworkermap.properties files in the
./conf folder in the Tomcat install directory. Below are samples of these properties files.

5
Isapi_redirect.properties
# Configuration file for the Jakarta ISAPI Redirector

# The path to the ISAPI Redirector Extension, relative to the website


# This must be in a virtual directory with execute privileges
extension_uri=/jakarta/isapi_redirect.dll

# Full path to the log file for the ISAPI Redirector


log_file=c:\tomcat1\logs\isapi_redirect.log

# Log level (debug, info, warn, error or trace)


log_level=info

# Full path to the workers.properties file


worker_file=c:\tomcat1\conf\workers.properties

# Full path to the uriworkermap.properties file


worker_mount_file=c:\tomcat1\conf\uriworkermap.properties

# Use the logs in the installation path of ISAPI Redirector


#log_file=$(ISAPI_PATH)\$(ISAPI_NAME).log

Uriworkermap.properties
/servlet/*=loadbalancer

/sm920/*=loadbalancer
/sm920=loadbalancer

/ROOT=loadbalancer
/ROOT/*=loadbalancer

/*.jsp=loadbalancer

[uri:/sm920/servlet/*]
info=Prefix mapping

[uri:/sm920/*.do]
info=Extension mapping

[uri:/sm920/*.jsp]
info=Extension mapping

[uri:/sm920/answers/attachments/*]
info=Prefix mapping

[uri:/sm920/attachments/*]
info=Attachment mapping

[uri:/sm920/logs/*]
info=Attachment mapping

[uri:/sm920/cwc/nav.menu]
info=Extension mapping

Workers.properties
worker.list=loadbalancer

6
worker.tomcat1.port=8009
worker.tomcat1.host=locahost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1

worker.tomcat2.port=9009
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1

worker.tomcat3.port=10009
worker.tomcat3.host=localhost
worker.tomcat3.type=ajp13
worker.tomcat3.lbfactor=1

worker.tomcat4.port=11009
worker.tomcat4.host=localhost
worker.tomcat4.type=ajp13
worker.tomcat4.lbfactor=1

worker.tomcat5.port=12009
worker.tomcat5.host=localhost
worker.tomcat5.type=ajp13
worker.tomcat5.lbfactor=1

worker.tomcat6.port=13009
worker.tomcat6.host=localhost
worker.tomcat6.type=ajp13
worker.tomcat6.lbfactor=1

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=tomcat1, tomcat2, tomcat3, tomcat4,
tomcat5, tomcat6

Once these properties files are in place, you can configure IIS. Open the Internet Information
Services Manager and navigate to your site. First, you will need follow these steps to configure the
ISAPI filter for that site:
1. Right-click on your site
2. Select Properties
3. Choose the ISAPI Filters tab
4. Click Add
5. Name the filter jakarta
6. Click Browse and select isapi_redirect.dll in <Tomcat_install_dir>/bin
7. Click OK to close the Add dialog

It is not necessary to restart IIS yet, this will be done at the end

8. Click OK to close the Properties dialog

Next, follow the below steps to add a virtual directory to your site:
1. Right-click on your site
2. Choose New/Virtual Directory
3. Click Next on the Wizard screen

7
4. Enter jakarta for the Alias and click Next
5. For the Path, click Browse and select <Tomcat_install_dir>/bin

This path must contain the isapi_redirect.dll

6. Click Next
7. Check the box for Execute, click Next
8. Click Finish

Next, we need to add an entry to enable the redirector in Web Service Extensions. To do this, follow
these steps:
1. Right-click on Web Service Extensions
2. Choose Add a new Web service extension…
3. Enter Jakarta-Tomcat for the name
4. Check the box for Set extension status to Allowed
5. Click Add
6. For the path, click Browse and select isapi_redirect.dll in <Tomcat_install_dir>/bin
7. Click OK

The configuration of IIS is now complete. Restart the IIS and WWW services from the Service Control
Panel to activate the configuration. Microsoft IIS Server will now act as the load balancer for multiple
tomcat instances as configured above.

8
For more information
Please visit the HP Software support Web site at:
www.hp.com/go/hpsoftwaresupport

This Web site provides contact information and details about the products, services, and support that
HP Software offers.
HP Software online software support provides customer self-solve capabilities. It provides a fast and
efficient way to access interactive technical support tools needed to manage your business. As a
valued customer, you can benefit by being able to:
 Search for knowledge documents of interest
 Submit and track progress on support cases
 Submit enhancement requests online
 Download software patches
 Manage a support contract
 Look up HP support contacts
 Review information about available services
 Enter discussions with other software customers
 Research and register for software training

Note: Most of the support areas require that you register as an HP Passport user and sign in. Many
also require an active support contract.
To find more information about support access levels, go to the following URL:
www.hp.com/go/hpsoftwaresupport/new_access_levels

To register for an HP Passport ID, go to the following URL:


www.hp.com/go/hpsoftwaresupport/passport-registration

Technology for better business outcomes


© Copyright 2011 Hewlett-Packard Development Company, L.P. The information
contained herein is subject to change without notice. The only warranties for HP
products and services are set forth in the express warranty statements
accompanying such products and services. Nothing herein should be construed as
constituting an additional warranty. HP shall not be liable for technical or editorial
errors or omissions contained herein.

Linux is a U.S. registered trademark of Linus Torvalds. Microsoft and Windows are
U.S. registered trademarks of Microsoft Corporation. UNIX is a registered
trademark of The Open Group. JavaScript is a registered trademark of Sun
Microsystems, Inc. in the United States and other countries. Oracle is a registered
trademark of Oracle Corporation and/or its affiliates

You might also like