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

[[email protected] ~]# sudo yum install java-1.8.0-openjdk.x86_64
[[email protected] ~]# 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)

[[email protected] ~]# sudo cd /opt/; wget
[[email protected] ~]# sudo tar -zxvf apache-tomcat-8.0.52.tar.gz
[[email protected] ~]# sudo cd apache-tomcat-8.0.52

Create the subdirectories of each instance directory.

[[email protected] ~]# sudo mkdir /var/lib/apache-tomcat-8.0.52

[[email protected] ~]# sudo mkdir -p /var/lib/apache-tomcat-8.0.52/{custserv,prodserv}

[[email protected] ~]# sudo mkdir -p /var/lib/apache-tomcat-8.0.52/custserv/{logs,conf,temp,webapps,work}
[[email protected] ~]# 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.

[[email protected] ~]# sudo cp -r /opt/apache-tomcat-8.0.52/conf/* /var/lib/apache-tomcat-8.0.52/custserv/conf
[[email protected] ~]# 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.

[[email protected] ~]# sudo ln -s /opt/apache-tomcat-8.0.52/bin /var/lib/apache-tomcat-8.0.52/custserv/bin
[[email protected] ~]# sudo ln -s /opt/apache-tomcat-8.0.52/bin /var/lib/apache-tomcat-8.0.52/prodserv/bin

[[email protected] ~]# sudo ln -s /opt/apache-tomcat-8.0.52/lib /var/lib/apache-tomcat-8.0.52/custserv/lib
[[email protected] ~]# sudo ln -s /opt/apache-tomcat-8.0.52/lib /var/lib/apache-tomcat-8.0.52/prodserv/lib

Create /usr/lib/systemd/system/tomcat-custserv.service and /usr/lib/systemd/system/tomcat-prodserv.service to configure the environment for each instance.

[[email protected] ~]# sudo vi /usr/lib/systemd/system/tomcat-custserv.service
Description=Apache Tomcat Web Application Container


Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'

ExecStop=/bin/kill -15 $MAINPID



Update same configuration for /usr/lib/systemd/system/tomcat-prodserv.service and change path.

Make sure user has created and updated for tomcat folders.

[[email protected] ~]# sudo useradd -s /bin/nologin -g tomcat -d /opt/apache-tomcat-8.0.52 tomcat
[[email protected] ~]# sudo cd /opt/apache-tomcat-8.0.52
[[email protected] ~]# sudo chgrp -R tomcat conf
[[email protected] ~]# sudo chown -R tomcat logs/ temp/ webapps/ work/ bin/ /lib

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

[[email protected] ~]# sudo systemctl start tomcat-prodserv.service
[[email protected] ~]# sudo systemctl start tomcat-custserv.service