Skip to main content

Multiple Tomcat Instances on Single Machine

In this post we will see how to run multiple tomcat instances on a single machine and under a single user account.

tomcat

Setup


We already see how to run tomcat in Ubuntu machine in my previous blog (http://kmlsarwar.blogspot.com/2014/08/how-to-install-apache-tomcat-on-ubuntu.html).

Step One—Create folder

Create two folder named "tomcat-instance1" and "tomcat-instance2" anywhere, and copy conf, logs, temp, webapps and work  folder from CATALINA_HOME folder and change conf/server.xml file in tomcat-instance1 and tomcat-instance2. we need to change 3 port shutdown port, connector port and ajp port.



Shutdown port - this port is used for shutdown the tomcat. when we call the shutdown.sh script they send signal to shutdown port. this port listen by tomcat java process. if signal is received the that process then its cleanup and exit by itself.

Connector Port -This port is actual port to expose the application to outside client. 

AJP port - this port is used to apache httpd server  communicate to tomcat. this port used when we setup load balanced server.

See the sample server.xml file:

<server port="8005" shutdown="SHUTDOWN">
.....
 <connector connectiontimeout="20000" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectport="8443">

<connector port="8009" protocol="AJP/1.3" redirectport="8443">
</connector></connector></server>


So we change these three port to different number, because once this port is binded  then other process can't bind it again. so wee bind different port. 

So tomcat-instance1/conf/server.xml file i configured server port =8105, connector port = 8181, ajp port = 8109.

And tomcat-instance2/conf/server.xml file i configured server port =8205, connector port = 8282, ajp port = 8209


Step Two—Create Script

 

Now we create two script file for startup and shutdown the tomcat-instance1 and tomcat-instance2.

startup-instance1.sh
export CATALINA_BASE=/usr/local/tomcat/tomcat-instance1
cd $CATALINA_HOME/bin
./startup.sh


startup-instance2.sh
export CATALINA_BASE=/usr/local/tomcat/tomcat-instance2
cd $CATALINA_HOME/bin
./startup.sh



shutdown-instance1.sh
export CATALINA_BASE= /usr/local/tomcat/tomcat-instance1
cd $CATALINA_HOME/bin
./shutdown.sh

shutdown-instance2.sh
export CATALINA_BASE= /usr/local/tomcat/tomcat-instance2
cd $CATALINA_HOME/bin
./shutdown.sh

Here we explicitly set the CATALINA_BASE variable and point to new tomcat-instance1 and
tomcat-instance1 the we go to CATALINA_HOME/bin folder because all binary for running tomcat is still present in CATALINA_HOME folder then startup/shutdown the script.

Based on above technique we can create many instance folder and change conf/server.xml file port values and run that instance with own newly created script files.


Step Three—Run

 

We need to give  permission to this scripts to execute. Then we run this script with this command

$ ./startup-instance1.sh
$ ./startup-instance2.sh

Once that runs, Two Tomcat are up and ready on port 8181 and 8282.

You can visually verify that Tomcat is working by accessing your server page at
 your_IP_address:8181 and  your_IP_address:8282

We can stop tomcat instance using the  shutdown script

$ ./shutdown-instance1.sh
$ ./shutdown-instance2.sh

This will shutdown the tomcat instance. Enjoy multiple instance of Tomcat!!!

 

 


Comments

Popular posts from this blog

JavaMelody: Monitoring the Performance of Tomcat Application Server

Javamelody is an opensource (LGPL) application to monitor Java or Java EE application servers in QA and production environments. JavaMelody is mainly based on statistics of requests and on evolution charts. (Extract from the Javamelody home page) It allows to improve applications in QA and production Give facts about the average response times and number of executions Make decisions when trends are bad, before problems become too serious Optimize based on the more limiting response times Find the root causes of response times Verify the real improvement after optimization It includes summary charts showing the evolution over time of the following indicators: Number of executions, mean execution times and percentage of errors of http requests, sql requests, jsp pages or methods of business façades (if EJB3, Spring or Guice) Java memory Java CPU Number of user sessions Number of jdbc connections These charts can be viewed on the current day, week, month, year or cu...

Tomcat Clustering : Session Replication with Backup Manager

Prerequisite Blogs: How To Install Apache Tomcat Multiple Tomcat Instances on Single Machine Tomcat Clustering: Loadbalancing with mod_jk and Apache Tomcat Clustering : Session Affinity    Backup Manager Backup manager usually used clustered environment. Its like delta manger. But it will  replicate to exactly one other instance(backup instance). Its act  like one instance is Primary  and another instance as backup. Steps to make Session Replication in Tomcat Clustering I am continue from exactly where I left in last session affinity post . So check that post and make sure jumRoute all are set properly. Steps are Enable Multicast routing Add <Cluster> Entries in conf/server.xml file for all instances. Enable the Web Application as distributable Step1:  Enable Multicast routing In Linux Environment most of the system kernel is capable to process the multicast address. We need to add...

Tomcat Clustering: Loadbalancing with mod_jk and Apache

We already see how to run multiple tomcat instance in a single machine in my previous blog ( http://kmlsarwar.blogspot.com/2014/08/multiple-tomcat-instances-on-single.html ). In this post we will see how to configure load balancing with mod_jk and Apache on Ubuntu. Suppose we have two hosts, node1 and node2 . Node1 runs an Apache and a Tomcat instance. On node2 we’ve got another Tomcat. A browser will connect to the host that’s running the Apache. Since the load on a single server running a web application can be pretty severe, we’re going to share the burden of serving servlets with multiple hosts (in our case two hosts). And we’re going to make mod_jk to do that for us. Steps to Implement Virtual Host/Loadbalancer Concept in this Scenario: Install Apache httpd Web Server  Install mod_jk connector  Configure JK Connector  Configure Apache httpd server, apply loadbalancer concepts Step One—Install Apache We can install Apache web ser...