Toll Free: 1800-383-5193
August 24th, 2009

How to Setup Additional Tomcat Instances on your Linux Server

by Prathyush Babu, Sr. Software Engineer, Bobcares.com


Tomcat is a stand-alone application web server which serves web pages containing Java Server Page(JSP) coding. It provides an environment to execute dynamic applications, like JSP and Java servlets. It communicates with Apache via mod_jk and support servlets and JSPs. 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.

JDK(Java Development Kit)

For proper execution, Tomcat requires JDK(Java Development Kit). JDK that contains API classes, Java compiler(javac), Java Virtual Machine(JVM) provides the basic tools to compile Java applications and applets.

Install JDK

You can download the latest version of JDK(JDK 7) from Sun’s Java web URL’s at:

http://java.sun.com/products/archive/index.html
http://java.sun.com/products/archive/j2se/1.4.2_08/index.html
http://java.sun.com/j2se/1.4.2/download.html

Unpack and install JDK in the directory /usr/local/. Now, we need to define the environment variable JAVA_HOME, such that it points to the java installation directory “/usr/local/jdk1.5.0“.

Add the following lines to the “/etc/bashrc” or “/etc/profile” file, so that the environment variable can be used by all aplications/users in the server.

JAVA_HOME=/usr/local/jdk1.5.0
export JAVA_HOME

Install Tomcat

The Tomcat complete package is available for download at the following URL :
http://tomcat.apache.org/download-55.cgi

Download the latest version of Tomcat and Install it in the /usr/local directory.

mv apache-tomcat-5.5.26.tar.gz /usr/local
tar -xvzf apache-tomcat-5.5.25.tar.gz

Now, create the following symbolic link.

ln -s /usr/local/apache-tomcat-5.5.25 /usr/local/tomcat

We can then run the Tomcat web server using a seperate user “tomcat”. Add the user and group “tomcat”.

groupadd tomcat
useradd -g tomcat -c "Tomcat User" -d /usr/local/tomcat tomcat
passwd tomcat <password for user>

Change the ownership of Tomcat installation directories.

chown tomcat:tomcat /usr/local/tomcat
chown -R tomcat:tomcat /usr/local/apache-tomcat-5.5.25

The installation of Tomcat is now complete. We can start the Tomcat instance using a startup script “/usr/local/tomcat/bin/startup.sh“. Also, make sure to define the variable CATALINA_HOME in the script “/usr/local/tomcat/bin/catalina.sh“.

CATALINA_HOME=/usr/local/tomcat

The default Tomcat configuration will service HTTP requests on port 8080. You can access this Tomcat instance using the URL https://server_IP:8080/, where server_IP is the address of the machine where we just now installed the Tomcat server.

In order to shut down the Tomcat service, use the script :

/usr/local/tomcat/bun/shutdown.sh

You can access the Tomcat Manager Interface corresponding to this Tomcat installation using the URL:

https://server_IP:8080/manager/

You can also configure the Manager Application Access using a username and password combination that has the role “manager” associated to them. All you have to do to enable this access is edit the Tomcat users configuration file.

/usr/local/tomcat/conf/tomcat-users.xml

By default, the Manager application is completely disabled. To enable access to the Manager web application, add the following entry in /usr/local/tomcat/conf/tomcat-users.xml.

<tomcat-users>
<role rolename="manager"/>
<user username="admin" password="tomcat" roles="manager"/>
</tomcat-users>

Once you restart the Tomcat service after this, you will be able to access the Manager interface using the login details admin/tomcat.

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 https://server_IP:8081 and the manager interface at https://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
http://azeditech.com/tomcat/multiple-tomcat-instances.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.


Post to Twitter Post to Facebook Post to MySpace

no-image

2 Comments »

  1. heilkräuter

    The process includes :
    Step 1: Install the Tomcat files
    Step 2: Make directories for each instance
    Step 3: Configure the ports and/or addresses for each instance
    Step 4: Startup

    Comment by heilkräuter — December 8, 2009 @ 1:29 pm

  2. ajai kumar

    Hi

    FYI! this is vinodh here! i have a doubt regarding “SYNFLOOD”

    Im running a webserver with apache,tomcat,the problem is tomcat is down,
    when i debugged,
    # messages.log i found this -
    (Kernel: possible SYN flooding on port 8009. Sending cookies)

    # mod.jk logs i found this -
    (Tomcat is down or refused connection. No response has been sent to the client (yet)

    # error.log i found this -
    server reached MaxClients setting, consider raising the MaxClients setting

    i know that the kernal have dropped the connections

    a) my doubt is this is a syn attack?
    b) does the syn attack is the reason for tomcat down?
    c) when there is a syn flood - i have an alert from my monitoring tool
    d)could plz clarify me

    does syn attack is responsible for tomcat down or does it is the increase in no of maximum clents as per error log is the cause of the tomcat down?

    i googled & searched all forums, but i’m yet to find a solution!

    please give me a solution?

    Comment by ajai kumar — January 20, 2010 @ 3:22 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Enter User Code

Visual CAPTCHA