multiple tomcat instance – single setup
running multiple tomcat by using a single catalina_base and catalina_home
this will make it easy to manage server management to use only one tomcat setup instance
download tomcat-6+ and unpack it.
and modify two configuration file under conf
replace ports & access log and cluster instance name with variables like:
<Server port="${tomcat.server.port}1" shutdown="SHUTDOWN">...
<Connector port="${tomcat.server.port}2" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />...
<Engine name="Standalone" defaultHost="localhost" jvmRoute="${tomcat.server.port}">
change log file prefix like
1catalina.org.apache.juli.FileHandler.prefix = ${tomcat.server.port}.catalina
and before you run the command you should set 2 enviroment varilable for each instance like
set JAVA_OPTS=-Dtomcat.server.port=810
set CATALINA_TMPDIR=%cd%..work810
catalina run
set JAVA_OPTS=-Dtomcat.server.port=820
set CATALINA_TMPDIR=%cd%..work820
catalina run
| NAME | SHUTDOWN | HTTP | AJP |
|---|---|---|---|
| 810 | 8101 | 8102 | 8103 |
| 820 | 8201 | 8202 | 8203 |
and you have 2 tomcat instance
for apache load balance setup see:
Complete Apache 2.2-AJP Load Balance via mod_proxy


참고
How can i install multiple tomcat instances sharing same web application i.e. there should be common place for web application shared by all tomcat server.
hi sanjeev,
in fact this installation works in a single directory and allows you run this single tomcat home multiple times by changing a single system property (environment variable). so all instances are running in a single directory.
to do like things you should change several conf file mentioned above:
server.xml
catalina.properties
and set tomcat.server.port for tomcat startup ports
Thanks Sir for reply
actually i have 4 tomcat instances with cluster setup e.g. tomcatA,tomcatB,tomcatC,tomcatD and have application in each server now whenever i need to change something in application i have to change in 4 places so i want a common place like C:/webapplication where i put my application and shared by all tomcat, so for this what should i need to change.
Thanks,
sanjeev
Hi again,
in this case there are multiple solutions,
first and most simple one is to use a context.xml file for your application and set a docBase eg: c:\webapplication
like: file:conf/Catalina/localhost/webapplication.xml
content:
<Context path="/webapplication" docBase="c:/webapplication">
</Context>
I hope this would help
Hello,
should i need to create webapplication.xml file in every tomcat instance or i need to put
this entry into context.xml file.
can you please give me a sample .xml file for the same
Thanks,
sanjeev
Hi,
I have give a sample in my previous post,
you should use this (webapplication.xml) file under:
CATALINA_BASE/ conf/Catalina/localhost/webapplication.xml
its content is just single line
<Context path=”/webapplication” docBase=”c:/webapplication”>
</Context>
and rest would work,
Hello,
Thanks for ur quick reply
i have done this, i have created ebapplication.xml file in each tomcat like (tomcatA\conf). but it is not using application from C:/webapplication path.
Should i remoce application from tomcat instance or is there another setting.
Thanks
Sanjeev
hi,
i have created webapplication.xml and put it into /webapps but it is not working…
webapplication.xml is :
please help..
Thanks,
Sanjeev
hi sanjeev ,
you should put it into CATALINA_BASE/conf/Catalina/localhost/
not in CATALINA_BASE/webapps
HI,
Thanks it’s working fine.
sanjeev
Hello ,
I have done tomcat clustering using Apache.and in my web application i have an HttpListener Class in which i am updating database for user log out when session timeout.
when one of tomcat instance in clustering is down then it’s session value is replicated to others and user do work properly.
Now My problem is when i shut down one of cluster instance then it call the Listener Class and updates the Database and marks the user as logout….
I do not want to call the listener class OR how can i know that tomcat is shut down e.g. any event that i can get so that i will not update database.
Please give your valuable ideas…..
Thanks,
Sanjeev
Hi I have just started on Clustring of Tomcat and load balancing. I do not have very much doc support for the clustering so please do guide me so that I can start working. Till Now I have changed the Port number of my 2 Tomcat instances in server.xml. But for each deployment I need to write http://localhost:port number/appName
That brings in my mind if the port number will changed then the context will change.
Kindly can u help me in installing tomcat multiple instances where am using Tomcat6.0 ….
Shyamala
Hai SIr,
I like to upload in a file in anything(docs,audio,video),In different machine tomcat server,How I will do,..Currently am doing in my project using more than tomcat server.
Thank u…
Have A ncE DAY…
Dear Altuure,
I am very new to tomcat installation. I COULD NOT make this “tomcat instances installation” to work successfully. Could you please help me.?
Platform : Linux
What i did is…:
——————
1. Extracted apache-tomcat-6.0.18
2. Tried to start the server with as it is in 8080 : –> was running fine.
3. Now as you told, as it is , i changed server.xml and catalina.properties.
4. I created a shell file named tomcatstartA.sh inside bin directory which contains:
set JAVA_OPTS=-Dtomcat.server.port=810
set CATALINA_TMPDIR=%cd%..work810
sh startup.sh
5. There is NO tomcatstartB.sh (First i am thinking to run only one server at least)
6. Now @command prompt i am running the following…
tomcat@server bin]$ chmod +x tomcatstartA.sh
tomcat@server bin]$ sh tomcatstartA.sh
Using CATALINA_BASE: /tomcatinstances/apache-tomcat-6.0.18
Using CATALINA_HOME: /tomcatinstances/apache-tomcat-6.0.18
Using CATALINA_TMPDIR: /tomcatinstances/apache-tomcat-6.0.18/temp
Using JRE_HOME: /usr/java/jre
tomcat@server bin]$ tail -f ../logs/catalina.out
Jul 25, 2011 12:12:38 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
===============================================================
WARNING: [SetPropertiesRule]{Server} Setting property ‘port’ to ‘${tomcat.server.port}1′ did not find a matching property.
===============================================================why this error ???
Jul 25, 2011 12:12:38 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/jre/lib/i386/server:/usr/java/jre/lib/i386:/usr/java/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib
Jul 25, 2011 12:12:38 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-0
Jul 25, 2011 12:12:38 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1008 ms
Jul 25, 2011 12:12:38 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jul 25, 2011 12:12:38 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.18
Jul 25, 2011 12:12:39 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Jul 25, 2011 12:12:39 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Jul 25, 2011 12:12:39 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-0
Jul 25, 2011 12:12:39 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jul 25, 2011 12:12:39 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/38 config=null
Jul 25, 2011 12:12:39 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1194 ms
root@server bin]# netstat -vatn | grep LISTEN
..
..
tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN
tcp 0 0 :::36358 :::* LISTEN
tcp 0 0 :::8009 :::* LISTEN
…
Everything i done is with user “tomcat”. So there will not be any problem in permission to access.
ServerA is started but WITH DEFAULT PORTS.. why so ?
can you please tell me that what mistake i have done ?
.
Hi,
It is a bit late but anyway…
How do you deal with file system resources? say the webapp writes to a file,
How this is going to work if I have 2 instances of this webapp running at the same time ?
Thanks
hi adi,
although depending on your requirements,IMHO writing to context folder is not a best practice
but in this approach since there should be only folder, you can use system property tomcat.server.port as a file prefix I guess ?
good luck
I understood my mistake..
I was using windows commands in Linux .. !!!!
set –> should be –> export..