Setting-up Multiple Apache Tomcat Instances In Linux(RHEL/CentOS)

I have already explained you how we can install & configure Apache Tomcat on a Linux server. Sometimes, we need to to have more than one instance of Apache Tomcat running on the same server. This is useful to divide the application load. We can divide the WAR files to be deployed among multiple instances so as to improve performance. So, lets learn how we can add multiple Apache Tomcat Instance. 🙂 But before that, a little explanation of this setup 😉

Multiple Tomcat instances means multiple directories where Tomcat is installed (known as catalina_home & catalina_base) & different ports on which the services listen. So, we will be creating one more directory (or rename the one that we get after unpacking Tomcat installer tarball) & editing the main configuration file server.xml. I assume that you already have one running instance of Tomcat. Refer to this post for more information.

Download the installer. Download the desired Apache Tomcat installer version from official website.

Unpack the tarball. Unpack the contents.

[root@server shashank]# tar -xf apache-tomcat-8.0.15.tar.gz

Rename the unpacked directory or Create a new directory to hold unpacked files. You will find a directory called apache-tomcat-8.0.15 in your current directory. You can choose to rename this or create a new directory & move the contents there.

[root@server shashank]# mv apache-tomcat-8.0.15 apache-tomcat

Edit script. Now we will edit the script so that it knows what is catalina_home & catalina_base. Always a good idea to backup the file(s) before editing 😉

[root@server apache-tomcat]# cp -p bin/ bin/
[root@server apache-tomcat]# vi bin/

Put below content above the text that says “OS specific support”. Make sure to use the path where you unpacked Tomcat.

#Exporting variables for this new instance.
export CATALINA_HOME=/opt/app/apache-tomcat
export CATALINA_BASE=/opt/app/apache-tomcat

Edit Tomcat configuration file. Edit the configuration file server.xml to use correct ports for Tomcat. Showing you the ports that need to be changed below. You can refer to the first instance’s server.xml to find the difference.

[root@server apache-tomcat]# cp -p /opt/app/apache-tomcat/conf/server.xml /opt/app/apache-tomcat/conf/server.xml.bkp
[root@server apache-tomcat]# vi /opt/app/apache-tomcat/conf/server.xml
Server port="8006" shutdown="SHUTDOWN"
Connector port="8081" protocol="HTTP/1.1"
     A "Connector" using the shared thread pool
    Connector executor="tomcatThreadPool"
               port="8081" protocol="HTTP/1.1"
   Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation that requires the JSSE
         style configuration. When using the APR/native implementation, the
         OpenSSL style configuration is required as described in the APR/native
    Connector port="8444" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"
Define an AJP 1.3 Connector on port 8009
Connector port="8084" protocol="AJP/1.3" redirectPort="8443"

Start Tomcat. Issue below command to start second instance of Tomcat.

[root@server apache-tomcat]# /opt/app/apache-tomcat/bin/
Using CATALINA_BASE: /opt/app/apache-tomcat
Using CATALINA_HOME: /opt/app/apache-tomcat
Using CATALINA_TMPDIR: /opt/app/apache-tomcat/temp
Using JRE_HOME: /opt/app/jdk1.8.0_25
Using CLASSPATH: /opt/app/apache-tomcat/bin/bootstrap.jar:/opt/app/apache-tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@server apache-tomcat]# netstat -tulnp | grep 80
tcp 0 0 ::ffff: :::* LISTEN 12824/java
tcp 0 0 ::ffff: :::* LISTEN 32287/java
tcp 0 0 :::8009 :::* LISTEN 12824/java
tcp 0 0 :::8080 :::* LISTEN 12824/java
tcp 0 0 :::8081 :::* LISTEN 32287/java
tcp 0 0 :::8084 :::* LISTEN 32287/java

So, you can see 2 Tomcat instances running on port 8005 & 8006 🙂 Hope, this was useful.