How to Run Multiple Tomcat Instances
Table of Contents
2. Tomcat server ports
3. Steps to configure multiple instances of tomcat on Linux
4. Common issues
5. Utility to create Tomcat Multiple Instances
Usually we come across situations where we need to run multiple instances of tomcat server in order to run different applications independent of each other. The situation where this is required is:
1) The tomcat server has been modified according to one particular application and it is not easy to segregate the server and application so that any other legacy/third-party application can be deployed on this tomcat server.
2) Two different user categories will be using the two different URL’s to access the server and this is a company/security requirement or one application has to run on a different port on the server for firewall issues.
Understanding Tomcat directory structure
When creating multiple instances of tomcat server, we need to play with the folders inside the server. These folders contain the actual scripts and code for the server. We have the option to either use the code base for tomcat in shared mode where all tomcat instances refer to the same physical code or we can create separate copies of these folder for each tomcat instance.
/bin : This directory contains the startup and shutdown scripts for both Windows and Linux.
/conf : This directory contains the main configuration files for Tomcat. The two most important are the server.xml and the global web.xml .
/server : This directory contains the Tomcat Java Archive files.
/lib : This directory contains Java Archive files that Tomcat is dependent upon.
/logs : This directory contains Tomcat’s log files.
/src : This directory contains the source code used by the Tomcat server. Once Tomcat is released, it will probably contain interfaces and abstract classes only.
/webapps : All web applications are deployed in this directory; it contains the WAR file.
/work : This is the directory in which Tomcat will place all servlets that are generated from JSPs. If you want to see exactly how a particular JSP is interpreted, look in this directory.
Source: Folder structure of tomcat
Tomcat server ports
Having a good understanding of tomcat ports is essential to manage the multiple instances of the same server installation. These ports are used by tomcat for start-up, deployment and shut-down operations. The detail of each port is as:
- Connector Port : This is the port where Apache Tomcat listen for the HTTP requests.
- Shutdown Port : This port is used when we try to shutdown the Apache Tomcat Server.
- AJP (Apache JServ Protocol) Connector Port : The Apache JServ Protocol (AJP) is a binary protocol that can conduct inbound requests from a web server through to an application server that sits behind the web server.
- Redirect Port : Any redirection happening inside Apache Tomcat will happen through this port. In Apache TOMCAT there are two instance where redirectPort is mentioned. First one is for the Apache TOMCAT server and other one is for the AJP port.
Steps to configure multiple instances of tomcat on Linux
1) Install Tomcat : For running two different tomcat servers, install/unzip tomcat into two different directories. I am assuming them to be /usr/tmp/tomcat1 and /usr/tmp/tomcat2. If you want to have more than two copies of tomcat running simultaneously, then create as many folders for the same. Deploy the corresponding web applications in to the webapps folder of the tomcat servers.
Other than the above scenario it is also possible to use the same tomcat base installation but using only the minimal directories. These minimal directories can be copied for tomcat1 to tomcat2 instead of installing fresh tomcat into /usr/tmp/tomcat2 folder. The minimal directories are bin, conf, webapps, temp and webapps.
2) Edit configuration:
I have also written about Tomcat terms and components used in steps given below.
The startup.sh and shutdown.sh script files make use of catalina.sh for performing the startup and shutdown operations. We shall edit catalina.sh file as described below:
a) For tomcat1, specify following three variables in catalina.sh script file present in the bin folder of the tomcat_home
b) For tomcat2, specify following three variables in catalina.sh script file present in the bin folder of the tomcat_home
c) In the /usr/tmp/tomcat2/conf directory, modify the server.xml file so that all ports which are currently in the format 8xxx are now in 6xxx format. We need to edit a minimum of three ports viz. start-up, shutdown and AJP. You can search for them in server.xml by using shutdown=”SHUTDOWN”, <Connector port= and protocol=”AJP/1.3″ strings. If you are using SSL with tomcat then you also need to provide a SSL port which is unique for all tomcat instances.
d) JAVA_HOME environment variable should be set and pointing to valid JDK or JRE location.
The above steps can also be applied on a tomcat installation on Windows operating system. The only changes required are the path and the CATALINA_HOME statement should be “set CATALINA_HOME=[PATH]“.
a) Modify the catalina.sh and server.xml using the vi editor and not any windows file editor.
b) Do not set CATALINA_HOME environment variable. If it is set, delete it. The script file catalina.sh will automatically handle this mandatory environment variable.
c) Do remember the port number updated in server.xml as the same will be required to access the new instance. For example, if you replaced 8080 with 6060 then the tomcat server url will be http://localhost:6060.
Utility to create Tomcat Multiple Instances
Recently, I created a tool for creating multiple instances of tomcat server. This tool works on Windows as well as Linux. The link to download the same is:
There is a readme.txt and help_document.doc included in the package to guide you in running the tool.
Note: This utility the other approach for creating multiple instances i.e. copying the minimal folders from base installation to new installations. It doesn’t require internet connection to create the multiple instances.