Additional Tomcat Instances

We have already installed one instance of Tomcat in the server. The basic directories associated with Tomcat, relative to $CATALINA_HOME, are:

/bin – Contains Startup, shutdown, and other scripts.

/conf – Contains configuration files. The main configuration file “server.xml” is present in this directory.

/logs – Contains related log files.

/webapps – Contains web applications.

We can still install multiple instances of Tomcat using the environment variable CATALINA_HOME. Each instance will use its own startup/shutdown scripts, configuration files, log files, etc.

Configure Second Instance

The first instance of Tomcat is installed inside the directory “/usr/local/tomcat“. In order to configure an additional instance, create a new directory “/usr/local/tomcat1“, assign correct permissions and copy all contents from the old directory to the new one.

mkdir /usr/local/tomcat1
chown tomcat:tomcat /usr/local/tomcat1
cp -pr /usr/local/tomcat/* /usr/local/tomcat1/

The Tomcat configuration is defined by the contents of the server.xml file that is found in the Tomcat’s configuration($CATALINA_HOME/conf) directory. In order to configure an additional instance, modify the tomcat configuration file corresponding to the second instance “/usr/local/tomcat1/conf/server.xml

Change AJP connector port from 8080 to 8081, because the first instance is already using 8080. The AJP connector port is used by Apache to forward requests. After modifications, it should look something like this:

<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector port="8081" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<!-- Note : To disable connection timeouts, set connectionTimeout value to 0 -->

Change the SHUTDOWN port from 8005 to 8115, because the the first instance already is using port 8005. Now the line should be like this:

<Server port="8115" shutdown="SHUTDOWN">

Yes, we are now done with the configuration of the second instance of Tomcat. Now we can start this instance using the startup script /usr/local/tomcat1/bin/startup.sh. Before that, it is required that you define the variable CATALINA_HOME as /usr/local/tomcat1 in the script /usr/local/tomcat1/bin/catalina.sh.

You can access this instance of Tomcat using the URL http://server_IP:8081 and the manager interface at http://server_IP:8081/manager/.

Similar to how we did initially, here too, you will need to manually add the “manager” user in the user configuration file /usr/local/tomcat1/conf/tomcat-users.xml.

Tomcat can be used as an independent web server, with its own internal HTTP server, or can be used in combination with other web servers, like Apache webserver.

In the same way, it is possible to install multiple Tomcat instances under different directories like /usr/local/tomcat2, /usr/local/tomcat3, etc.

It is important that the ports required for Tomcat connections are kept open in the server firewall.

The above installation steps has been tried and tested using Tomcat 5.x. In the above example, multiple instances are using the same version of Tomcat. However, it is possible to run different Tomcat versions for multiple instances in the same server. For that, while configuring the second instance, download and install an alternate Tomcat version(Tomcat 6.x) in the directory /usr/local and create the following symbolic link.

ln -s /usr/local/apache-tomcat-6.0.18 /usr/local/tomcat1

And then, proceed with the same steps as of the second instance.

By installing multiple instances, you can improve performance and easiness of the web application management. Also, it helps to improve the stability of web applications. On multi-user systems (with developers working), it is often useful to set up Tomcat, so that each user runs a separate instance of Tomcat.

Reference

http://tomcat.apache.org/tomcat-5.5-doc/index.html
http://tomcat.apache.org/tomcat-4.0-doc/manager-howto.html


About the Author :

Prathyush Babu has been working with Bobcares for over 3.5 years and he is an expert when it comes to Data Center Support Management. Prathyush loves to explore various Unix flavors and has a high degree of interest towards Server Security and Bash Scripting. He has a vast experience handling several control panels and brings in a lot of flexibility into the company, with his knowledge in various areas of the Hosting industry. Prathyush is cheerful and is a fun lover. Music, Painting and Travelling are some of his hobbies.