Hello @Ganesh,
To run and configure multiple instances in a Single Tomcat Server do follow the steps:
First, you need to download Tomcat(I downloaded the Core .zip file.)
Now unzip the file and rename the folder “Tomcat.” You will get the below folder structure.
Now suppose we want to run two instances on this single Tomcat.
Instance 1: edureka-one
Instance 2: edureka-two
First I want to create the edureka-one instance.
So make a copy of your downloaded Tomcat, and rename the folder “edureka-one,” and keep only “bin,” “conf,” “logs,” “temp,” “webapps,” and “work” files only.
Now remove all the files from edureka-one/bin. In the “bin” folder of “app-one,” you can add a setenv.sh file to configure the JVM heap setting for that tomcat instance.
setenv.sh
export CATALINA_OPTS="$CATALINA_OPTS -Xms256m"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx1024m"
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=512m"
Now make another copy of the “edureka-one” folder and rename it “edureka-two.”
Now we have three folders in our directory
1) Tomcat
2) edureka-one
3) edureka-two
Now go to the “Tomcat” directory and delete the “conf,” “logs,” “temp,” “webapps,” and “work” folders. Create a new folder named “controller” inside Tomcat. In the “controller” folder, we will write a script to control all the Tomcat instances. Now, inside our Tomcat folder, we have:
Now we will configure all the Tomcat instances (“edureka-one”, “edureka-two”) to different ports.
Configuration for edureka One
Go to this location, edureka-one/conf/, and open server.xml in edit mode. Suppose we want to run edureka-one in the “7050” port. Here is our configuration:
<?xml version='1.0' encoding='utf-8'?>
<Server port="7005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="adminApp">
<Connector port="7050" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="7543" />
<Connector port="7509" protocol="AJP/1.3" redirectPort="7543" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
Configuration of edureka Two
Go to this location, app-two/conf/, and open server.xml in edit mode. Suppose we want to run app-two in “7060” port. Here is our configuration:
<?xml version='1.0' encoding='utf-8'?>
<Server port="7006" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="adminApp">
<Connector port="7060" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="7643" />
<Connector port="7609" protocol="AJP/1.3" redirectPort="7643" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
Note that any port number must not conflict with other port numbers.
Now we are going to write startup.sh and shutdown.sh inside the "tomcat/controller" location to start and stop each individual instance of tomcat.
startup.sh
#!/usr/bin/env sh
app_instance=$1;
BASE_TOMCAT=/location-to-tomcat-parent-directory
export CATALINA_HOME=$BASE_TOMCAT/tomcat
export CATALINA_BASE=$BASE_TOMCAT/$app_instance
$CATALINA_HOME/bin/startup.sh
shutdown.sh
#!/usr/bin/env sh
app_instance=$1;
BASE_TOMCAT=/location-to-tomcat-parent-directory/
export CATALINA_HOME=$BASE_TOMCAT/tomcat
export CATALINA_BASE=$BASE_TOMCAT/$app_instance
$CATALINA_HOME/bin/shutdown.sh
Everything is ready now. Copy paste your edureka-one.war file into “edureka-one/webapps” location and edureka-two.war file into “edureka-two/webapps” location and rename both files as ROOT.war .
Now you can start your apps using the following commands:
-
./startup.sh edureka-one
-
./startup.sh edureka-two
Our edureka-one URL, http://localhost:7050, and edureka-two URL, http://localhost:7060,
stop apps by using following commands:
This way, you can run more than one instance in a single Tomcat with different configurations on each instance.
Hope this work!!
Thank you!!!