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 need 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.
Steps to configure multiple instances of Tomcat server
I am using a windows machine you I will be using the paths in windows format. But the procedure to create multiple instances is same in all other operating systems. Also, I am assuming that you want to create 2 new different instances of tomcat. Now start reading the complete steps to achieve the goal.
Step 1) Install Tomcat Server
This is very obvious step to be in first place. Let’s say our tomcat installation directory is “C:/tomcatServer“.
Step 2) Create 2 new different folders in different locations
These folders are for storing the instance specific configuration and other data such as logs, temp data.
Let’s say new folders are “C:/tomcatInstanceOne” and “C:/tomcatInstanceTwo“.
Step 3) Copy the ‘conf’ folder into instances folder from server folder
This step is necessary to have different configuration for each instance. Any instance specific configuration related changes should be done in related instance folder only.
Step 4) Create instance specific startup.bat and shutdown.bat
These files will be needed to start and shutdown a particular instance. The content of the files will be as below:
startup.bat
set CATALINA_HOME=C:\tomcatServer set CATALINA_BASE=C:\tomcatInstanceOne C:\tomcatServer\bin\startup.bat |
shutdown.bat
set CATALINA_HOME=C:\tomcatServer set CATALINA_BASE=C:\tomcatInstanceOne C:\tomcatServer\bin\shutdown.bat |
Place both files in ‘bin‘ folder inside both instance specific folders. [e.g. Create folder C:/tomcatInstanceOne/bin and copy both files].
The first properties (CATALINA_HOME) points to the location of the common information shareable between all running instances, while the other property (CATALINA_BASE) points to the directory where all the instance specific information are stored.
Step 5) Create setenv.bat for setting instance specific environment configuration
Create a file called setenv.bat in the “C:\tomcatInstanceOne\bin” (and in second instance folder as well) directory to set any environment variables mentioned in C:\tomcatServer\bin\catalina.bat. This is the place to set system properties, JPDA addresses, etc.
Step 6) Create more folders for logs, temp etc.
Now it’s time to create more folders which will be used when your application will be actually running. These folders are like logs, temp, webapps and work. Create them in both instance folders separately.
Just be sure to edit your conf\server.xml file so that the shutdown ports and HTTP connector ports don’t interfere with other tomcat instances that may be running.
e.g. Change the ports where tomcat will be running/debugging.
First server.xml file < connector port = "8080" protocol = "HTTP/1.1" connectionTimeout = "20000" redirectPort = "8443" /> < server port = "8005" shutdown = "SHUTDOWN" /> < connector port = "8009" protocol = "AJP/1.3" redirectPort = "8443" /> < connector port = "8100" protocol = "HTTP/1.1" connectionTimeout = "20000" redirectPort = "8443" /> Second server.xml file < connector port = "8081" protocol = "HTTP/1.1" connectionTimeout = "20000" redirectPort = "8443" /> < server port = "8006" shutdown = "SHUTDOWN" /> < connector port = "8010" protocol = "AJP/1.3" redirectPort = "8443" /> < connector port = "8101" protocol = "HTTP/1.1" connectionTimeout = "20000" redirectPort = "8443" /> |
After doing above changes you should be able to launch multiple instances of same tomcat server in your machine. Please let me know if you are struck somewhere.