Configure multiple Tomcat instances on single server

Learn how to set up several different instances of an application on your Tomcat server, and manipulate each of these instances independently. This article will explain to you how to configure multiple Tomcat instances on single server.

Many times we come to a situation where we need to modify the server configuration such that it is specific to an application. And if we got more than one such applications and we want each application to have it’s own defined configuration options, then it needs some sort of configuration. In this tutorial, I am going to discuss the changes you should make to have different instances of tomcat for each application.


Install JAVA

[centos@localhost ~]# sudo yum install java-1.8.0-openjdk.x86_64
[centos@localhost ~]# sudo java -version
openjdk version “1.8.0_141”
OpenJDK Runtime Environment (build 1.8.0_141-b16)
OpenJDK 64-Bit Server VM (build 25.141-b16, mixed mode)

[centos@localhost ~]# sudo cd /opt/; wget
[centos@localhost ~]# sudo tar -zxvf apache-tomcat-8.0.52.tar.gz
[centos@localhost ~]# sudo cd apache-tomcat-8.0.52

Create the subdirectories of each instance directory.

[centos@localhost ~]# sudo mkdir /var/lib/apache-tomcat-8.0.52

[centos@localhost ~]# sudo mkdir -p /var/lib/apache-tomcat-8.0.52/{custserv,prodserv}

[centos@localhost ~]# sudo mkdir -p /var/lib/apache-tomcat-8.0.52/custserv/{logs,conf,temp,webapps,work}
[centos@localhost ~]# sudo mkdir -p /var/lib/apache-tomcat-8.0.52/prodserv/{logs,conf,temp,webapps,work}

Copy the conf directory from the default Tomcat installation into each instance.

[centos@localhost ~]# sudo cp -r /opt/apache-tomcat-8.0.52/conf/* /var/lib/apache-tomcat-8.0.52/custserv/conf
[centos@localhost ~]# sudo cp -r /opt/apache-tomcat-8.0.52/conf/* /var/lib/apache-tomcat-8.0.52/prodserv/conf

Create symbolic links to the default bin and lib locations.

[centos@localhost ~]# sudo ln -s /opt/apache-tomcat-8.0.52/bin /var/lib/apache-tomcat-8.0.52/custserv/bin
[centos@localhost ~]# sudo ln -s /opt/apache-tomcat-8.0.52/bin /var/lib/apache-tomcat-8.0.52/prodserv/bin

[centos@localhost ~]# sudo ln -s /opt/apache-tomcat-8.0.52/lib /var/lib/apache-tomcat-8.0.52/custserv/lib
[centos@localhost ~]# sudo ln -s /opt/apache-tomcat-8.0.52/lib /var/lib/apache-tomcat-8.0.52/prodserv/lib


Change default ports in prodserv/conf/server.xml and make sure ports 8080,8005,8009 are not conflicting with custserv/conf/server.xml.  We changed default ports in custserv/conf/server.xml.

Now, we are going to create the user and group of Apache, for that we are going to execute the following:

[centos@localhost ~]# sudo groupadd tomcat 

[centos@localhost ~]# sudo useradd -s /bin/false -g tomcat -d /opt/apache-tomcat-8.0.52/ tomcat


Now, let’s change the owner of the tomcat directory to the user and tomcat group:

[centos@localhost ~]# sudo chown -R tomcat.tomcat  /opt/apache-tomcat-8.0.52/  /var/lib/apache-tomcat-8.0.52/custserv/ /var/lib/apache-tomcat-8.0.52/prodserv

Start Tomcat Services

we will execute a test to make sure that everything is working the way we want, for this we will execute the following:

[centos@localhost ~]# sudo cd /var/lib/apache-tomcat-8.0.52/prodserv/bin

[centos@localhost ~]# sudo ./

We can see that everything is correct in the “Tomcat started” line. Tomcat runs by default on port 8080.

[centos@localhost ~]# sudo cd /var/lib/apache-tomcat-8.0.52/custserv/bin

[centos@localhost ~]# sudo ./

We have changed the default tomcat port to 8081.

Enable ports 8080 and 8081 on your Firewall.

Create a sample page on your webapps directory /var/lib/apache-tomcat-8.0.52/custserv/webapps/sample and access Apache Tomcat service to validate its installation.

http://<host>:8080/sample and http://<host>:8081/sample