I am trying to run multiple instances of Tomcat, but even after configuring different ports for listening and shutting down the second instance, it keeps trying to listen on 8080 (configured for 8081). I read that I have to set a different value for CATALINA_BASE
. From all the articles there are online, none of them actually show in which file this variable can be set.
Where and how can I set CATALINA_BASE for my Tomcat instance in C:\apache-tomcat-7.0.39
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. Change the Connector port=”8080″ port to any other port number.
In a section that shortly explains the architecture of the container he says: "Only one tomcat instance can live in a single Java Virtual Machine(JVM)..." later, the author states: "You can still run multiple instances on same physical box, but as separated Java processes..." What is actually the meaning of running the ...
Simply drop both war files into Tomcat's webapps folder. That is all you need to do. By default, Tomcat expands ("explodes" some say) each war (technically a zip file) into a folder and automatically deploys the app for you. This happens on the fly if Tomcat is already running, or on startup when you launch Tomcat.
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):
<Server port="XXXX" shutdown="SHUTDOWN">
<Connector port="XXXX" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Connector port="XXXX" protocol="AJP/1.3" 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
The easiest way I have run two copies of Tomcat involved the following steps (I was trying to run two distinct versions of tomcat, 6 and 7):
Establish 2 copies of tomcat in different folders (if they are different versions then this is easy, if they are the same version then you will need be distinguished in some other way. There are a lot of files that Tomcat creates to manage it so running two instances with the same work directory likely isn't possible)
Change the following ports that tomcat is listening to in server.xml
<Connector port="8080">
<- This is the port that tomcat uses to respond to HTTP requests<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<- this defines two ports, one for the AJP connector (used if you are using tomcat behind an Apache or IIS server) and the port used for HTTPS traffic<Server port="8005" shutdown="SHUTDOWN">
<- this is the port that Tomcat uses to respond to SHUTDOWN eventsFinally, if you are running this as a Windows service you will need to establish different service names for each instance (you can do this during setup, the default for Tomcat 7 is tomcat7). Once Tomcat is running all of it's configuration fields use relative paths so you don't need to touch CATALINA_BASE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With