Can I run two tomcat instances on the same machine?

JavaTomcat

Java Problem Overview


Can I run two Tomcat servers with two different ports on the same machine? Will it create any problem? When I run a tomcat it will create the javaw.exe file in the task manager.

Java Solutions


Solution 1 - Java

Apart from changing Connector port for protocol="HTTP/1.1" described in one of the answers below.

I think it requires to change Server port for 'Shutdown'

<Server port="8005" shutdown="SHUTDOWN">

and also AJP port no.

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

If you want to run multiple tomcat instances in parallel.

Solution 2 - Java

Yes !. You can. You need to change your port to have another instance.

To do so follow the steps.

1.) Locate server.xml in {Tomcat installation folder}\ conf \

2.)Find following similar statement

<!-- Define a non-SSL HTTP/1.1 Connector on port 8180 -->
    <Connector port="8080" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />

3.) About Tomcat’s server.xml file cites it’s runs on port 8080. Change the Connector port=”8080″ port to any other port number.

For example

<Connector port="8181" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />

4) Edit and save the server.xml file. Restart Tomcat. Done

Solution 3 - Java

Yes, that's absolutely fine. I've done it on numerous occasions. You'll need to check all the ports you're using for Tomcat though. I can't remember whether it still has a special "local control" port, but if so those will need to be different too.

Solution 4 - Java

In general we also set CATALINA_HOME property. so startup script first reads catalina_home and than from it figures out rest of the path. If this environment variable is set and if you try to run tomcat from any copy-paste tomcat installation location, you will get tomcat running which is pointed by CATALINA_HOME.

So while running two tomcat from same machine, remove the CATALINA_HOME property. That way it will set the CATALINA_HOME property based on directory from which you are running the startup script.

Solution 5 - Java

Adding a few pointers to detailed instructions on how to accomplish that:

  1. Step by step Running Multiple Tomcat Instances on One Server.
  2. An older version of the above.
  3. Explanation of various environment variables & folders that play a role in such setup.

Solution 6 - Java

Here is my expperience/process of making two Tomcats (Tom1 and Tom2) running on Windows:

  1. Setup Tomcat according to http://www.ntu.edu.sg/home/ehchua/programming/howto/Tomcat_HowTo.html

  2. However, Tom1 starts up fine, but not Tom2.

  3. So in addition to the above, in server.xml, make/change the following (on Tomcat 6.0.44, JDK 1.6.0_45):

    Line 22: Tom1 shutdown port = 9001
    Line 22: Tom2 shutdown port = 9002

    Line 53: Tom1 service name = "Catalina1"
    Line 53: Tom2 service name = "Catalina2"

    Line 69: Tom1 connector (http) = 9001
    Line 69: Tom2 connector (http) = 9002

    Line 71: Tom1 redirect port = 8443
    Line 71: Tom2 redirect port = 8444

    Line 90: Tom1 connector (ajp) = 8009
    Line 90: Tom1 redirect = 8443
    Line 90: Tom2 connector (ajp) = 8010
    Line 90: Tom2 redirect = 8444

    Line 102: Tom1 engine name = "Catalina1"
    Line 102: Tom2 engine name = "Catalina2"

  4. Starting up each server

Voila!

Solution 7 - Java

I've faced a similar situation and the answer mentioned here, solves it in much crisp and simple fashion.

> Let's say that you have only one Tomcat folder located in C:\apache-tomcat-7.0.39, and that you wish to run two instances from it. > > Make sure that you have CATALINA_HOME system/user variable set, and > pointing to C:\apache-tomcat-7.0.39 > > Create a folder C:\instance1. Copy conf, webapps and temp folders from > C:\apache-tomcat-7.0.39 and paste them to C:\instance1. You can delete > contents from webapps and temp folders located under instance1, but > don't touch conf contents. Now copy>paste C:\instance1 and rename it > to instance2. That way, both instance1 and instance2 will have the > same content. Go to C:\instance2\conf, edit server.xml and change the > numbers of these ports (I marked those as XXXX): > > > > redirectPort="8443" /> > > > Deploy whatever you want into instance1\webapps and instance2\webapps > Create the following 4 batch files under C:
> > instance1_startup.bat > > @echo off >
> set CATALINA_BASE=C:\instance1 >
> cd "%CATALINA_HOME%\bin" >
> set TITLE=My Tomcat Instance 01 >
> call startup.bat %TITLE% > > instance1_shutdown.bat > > @echo off >
> set CATALINA_BASE=C:\instance1 >
> cd "%CATALINA_HOME%\bin" >
> call shutdown.bat > > instance2_startup.bat > > @echo off >
> set CATALINA_BASE=C:\instance2 >
> cd "%CATALINA_HOME%\bin" >
> set TITLE=My Tomcat Instance 02 >
> call startup.bat %TITLE% > > instance2_shutdown.bat > > @echo off >
> set CATALINA_BASE=C:\instance2 >
> cd "%CATALINA_HOME%\bin" >
> call shutdown.bat > > Run instance1_startup.bat and instance2_startup.bat, hopefully it > should work.

Solution 8 - Java

you can run unlimited instances of tomcat on your server/pc, ofcourse you need to define each one with different port.

Solution 9 - Java

As already discussed here, you can either omit the CATALINA_HOME environment variable and use the catalina.sh script to manage your container's life cycle or you could define another variable like CATALINA_HOME1 to point to the new tomcat's installation directory and modify it's catalina.sh script to use CATALINA_HOME1 instead of the original CATALINA_HOME reference.

In any case, you could avoid it all together by omitting any environment variable named CATALINA_HOME references and just link to the corresponding tomcat's catalina.sh script.

example:

cd /usr/sbin
ln -s /usr/local/java/apache-tomcat-6.0.37/bin/catalina.sh catalina1
ln -s /usr/share/java/apache-tomcat-6.0.37/bin/catalina.sh catalina2

Then start your tomcats like this (from anywhere):

catalina1 start
catalina2 start

Tom

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkrishnaView Question on Stackoverflow
Solution 1 - JavaHardik MishraView Answer on Stackoverflow
Solution 2 - JavaAshfak BaloochView Answer on Stackoverflow
Solution 3 - JavaJon SkeetView Answer on Stackoverflow
Solution 4 - JavaBookieView Answer on Stackoverflow
Solution 5 - JavaWithheldView Answer on Stackoverflow
Solution 6 - JavaDaniel C. DengView Answer on Stackoverflow
Solution 7 - JavaUttamView Answer on Stackoverflow
Solution 8 - JavaEladView Answer on Stackoverflow
Solution 9 - JavaTom SilvermanView Answer on Stackoverflow