63

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.

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
krishna
  • 681
  • 2
  • 6
  • 6
  • 1
    Task manager sidenote: it only list processess. The javaw.exe you see is only the name of the executable launched but it's not creating any new file. Is like when you create two instances of a class. The exe file is like the class and the processes are the instances :) – helios Jan 13 '11 at 09:02
  • 1
    If any of these solved your problem, you should probably accept the one that worked. – Stefan Thyberg Feb 23 '12 at 15:04

9 Answers9

69

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.

Hardik Mishra
  • 14,779
  • 9
  • 61
  • 96
  • 1
    Good and neath answer, just as an add on, besides Connector port, Shutdwon port, and AJP port, you may want to change Connector port for SSL as well: – Diego Duarte Sep 22 '15 at 10:58
31

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

Ashfak Balooch
  • 1,879
  • 4
  • 18
  • 30
  • 3
    Do not forget about SHUTDOWN port (at the very beginning of `server.xml` config file. Also you can use this tutorial -- http://crunchify.com/how-to-run-multiple-tomcat-instances-on-one-server/ – Lord Nighton Jan 09 '16 at 17:21
12

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • @krishna, note that if you find an answer useful, you can (and should) upvote it by clicking on the up arrow on its left :-) – Péter Török Jan 13 '11 at 08:38
  • And one additional recommendation. You will probably wish to create separate log files for each instance of tomcat. In this case use -Dlog4j.properties to pass log configuration for each tomcat instance. – AlexR Jan 13 '11 at 08:38
  • 4
    With "all ports" Jon means at least Non-SSL, SSL, shutdown and AJP. – Costis Aivalis Jan 13 '11 at 09:23
  • I am able to run it by changing the port numbers... Thanks – krishna Jan 19 '11 at 09:28
7

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.

Bookie
  • 93
  • 1
  • 6
7

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.
Withheld
  • 4,603
  • 10
  • 45
  • 76
5

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!

Daniel C. Deng
  • 1,573
  • 13
  • 8
3

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):

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.

Community
  • 1
  • 1
Uttam
  • 576
  • 5
  • 17
1

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

Tom Silverman
  • 634
  • 1
  • 8
  • 7
1

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

Elad
  • 479
  • 3
  • 11
  • 21