can i run two tomcat servers on the same linux VM machine

0 votes
I want to run tomcat 8 and tomcat 9 on my linux VM. Both are intended for different purposes. So is it possible to do so?
May 28, 2019 in Java by Neel
• 3,020 points

edited May 28, 2019 by Neel 5,716 views

2 answers to this question.

0 votes
Yes its possible. I had installed tomcat 7 and tomcat 8 on my linux VM. You just need to make sure that the port numbers for the two tomcat instances are different.
answered May 28, 2019 by arvind.phulare1911
• 180 points
Edureka tech support team is trying to install multiple instance of tomcat servers onto two different ports, but sinc almost 1 week they are not able to do the same.  At a given time only one port is working.  Do let us know configuration steps.

Thanks

Hi@Ganesh,

One port no. can be used by only one program. By default Tomcat server works on port no. 8080. So if one Tomcat server is working on port 8080, then another Tomcat server can't use the same port. So you need to change the port no. of your second Tomcat server. You can follow the below steps. Or you can find lots of documents on google.

  • Locate the file server.xml inside the Tomcat configuration folder.
  • In server.xml, find a statement similar to the following.
<Connector port="8080" protocol="HTTP/1.1"
   connectionTimeout="20000"
   redirectPort="8443" />
  • Change the Connector port=”8080″ port to any other port number.

<Connector port="8181" protocol="HTTP/1.1"
   connectionTimeout="20000" 
   redirectPort="8443" />
  • Save the server.xml file and restart the Tomcat server.

0 votes

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.

Image title

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.

Image title

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:

Image title

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:

  • ./shutdown.sh edureka-one 

  • ./shutdown.sh edureka-two 

This way, you can run more than one instance in a single Tomcat with different configurations on each instance.

Hope this work!!

Thank you!!!

answered Jul 30, 2020 by Niroj
• 82,840 points

Related Questions In Java

0 votes
1 answer

How can we run the .jar file by double clicking on windows 7 (64)?

Use the following method to run the ...READ MORE

answered Jun 28, 2018 in Java by sharth
• 3,370 points
1,846 views
0 votes
2 answers

What is the use of toString method in Java and how can I use it ?

Whenever you require to explore the constructor ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,140 points
4,090 views
0 votes
2 answers

How can I invoke a method when the method name is in the form of a given string?

You could probably use method invocation from reflection: Class<?> ...READ MORE

answered Aug 19, 2019 in Java by Sirajul
• 59,230 points
3,058 views
0 votes
2 answers

How can I get the filenames of all files in a folder which may or may not contain duplicates

List<String> results = new ArrayList<String>(); File[] files = ...READ MORE

answered Sep 12, 2018 in Java by Sushmita
• 6,920 points
1,901 views
+1 vote
6 answers

How can I separate the digits of an int number in Java?

You can also have a look here: To ...READ MORE

answered Dec 9, 2020 in Java by Roshni
• 10,520 points
209,721 views
0 votes
1 answer

How can I make the return type of a method generic?

First of all, define callFriend: public <T extends ...READ MORE

answered May 19, 2018 in Java by sharth
• 3,370 points
783 views
0 votes
1 answer
0 votes
1 answer

How can a war file be deployed in Tomcat 7?

You can access your application from: http://localhost:8080/sample Deploying ...READ MORE

answered Apr 20, 2018 in Java by sophia
• 1,400 points
2,080 views
0 votes
1 answer
0 votes
1 answer

Serverspec doesn't check package version correctly

Specinfra is escaping the characters in the with_version chain ...READ MORE

answered Aug 2, 2018 in DevOps Tools by Kalgi
• 52,350 points
1,320 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP