aspose file tools*
The moose likes Tomcat and the fly likes Two instances of Tomcat on the same OS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Two instances of Tomcat on the same OS" Watch "Two instances of Tomcat on the same OS" New topic
Author

Two instances of Tomcat on the same OS

Chanakya Gupta
Ranch Hand

Joined: May 23, 2010
Posts: 34

I am new to this forum.

How to configure 2 JVMs, 2 Tomcats on the same OS ?
1. Is it possible ? If the answer is 'Yes', then,
2. How to have 2 different JAVA_HOME and JRE_HOME ?
3. Both Tomcats point to the same JRE_HOME, how can
we make the 2nd Tomcat point to the 2nd JRE ?


My aim is to test the HttpSession object's lifecycle on
2 JVMs as described in the book 'Head First Servlets and JSP',
on page 257, 'The Beer Web App distributed on two JVMs'


My Setup is -
1. Installed one JVM in '/usr/local' and
2nd JVM in '/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0'
JAVA_HOME is '/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0'
JRE_HOME is '/usr/lib/jvm/jre-1.6.0-openjdk'
2. OS is Fedora.
3. Installed two Tomcats, one in /usr/local/tomcat1
and 2nd in /usr/local/tomcat2
4. Created TC1_HOME=/usr/local/tomcat1 and
TC2_HOME=/usr/local/tomcat2

Thankyou in advance.

SCJP6, SCWCD5, SCMAD
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hello Chanakya,

yes it is possible to host many Tomcats on the same machine!

In any case you have to take care that the ports used by each Tomcat instance don't overlap. That means, depending on the configuration in the server.xml file, you have to configure different port numbers for the shutdown port, the HTTP and HTTPS connector and the AJP connector (if you use all these connectors).
Another possibility is to have multipe IP addresses and configure each Tomcat to use another IP so ports can't conflict.

To your question regarding the JVMs: Do you really want to use two DIFFERENT JVMs or just two instances of the JVM? If you mean two instances of the JVM you don't have to worry about this because each Tomcat will start in its own JVM anyway.

If you really want to configure different JVMs you can export the JAVA_HOME or JRE_HOME environment variables inside the involved startup scripts. A good place could be the catalina.sh/catalina.bat script of the Tomcat installation itself though you have to take care to maintain this when upgrading Tomcat. Or you could set these environment variables inside the shell or batch script used to startup Tomcat. This depends on the OS used, so in your case you could create one or multiple shell scripts to start Tomcat.

Clearer now??

Btw.: I have recently played around with multiple Tomcats and session replication and migration on my machine. You don't have to worry about the Java environment variables for this as I said. But it's helpful to have some scripts which help you to manage multiple Tomcats or generate the server.xml files with different ports for each Tomcat. Of course it's not that much work with only two Tomcats...

Marco
Chanakya Gupta
Ranch Hand

Joined: May 23, 2010
Posts: 34

Thankyou Marco !

Running two instances of Tomcat with the same JAVA_HOME and JRE_HOME
is possible. This implies the same JVM.

How to achieve what the book says,
'Beer Web App distributed across two VMs' ?

We need two distinct VMs, on the same OS. Right ?

Thankyou in advance !
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Sorry, but I don't know "the book"

But I know what you mean As I said it IS possible to run multiple Tomcats with multiple JVMs on the same machine. You don't have to do anything to achieve this because each Tomcat starts its own JVM anyway. It's the same as starting any application on your computer twice although you just have to install the application once. So there is one installation of Java (to which JAVA_HOME should point) and two installations of Tomcat (because it's the easiest way to have different Tomcat configuration files). And each started Tomcat automatically runs in its own instance of the JVM. I don't even know if it would theoretically be possible to run two Tomcat instances insided only one JVM...

You would have to take care about setting a different JAVA_HOME only if you wanted to use different VERSIONS of the JVM!

But as easy as it may sound it's not trivial to setup a Tomcat cluster with session replication and/or failover. You have to configure the Tomcats correctly and for failover it's almost necessary to have something like an Apache HTTP server as a "frontend" to your Tomcat backend servers to see an effect from the user perspective. A solid understanding of networking in general could be helpful, too.

As I said, I don't know what this book tells you but I hope my information can guide you to your goal. I you still experience problems just let us know

Marco
Chanakya Gupta
Ranch Hand

Joined: May 23, 2010
Posts: 34

Thankyou Marco !
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

at the time of doing the installation of Tomcat.

There is option of selecting the path of a j2se 5.0 JRE installed on your system.

You can select the sameJVM or a different one installed somewhere else.


SCJP6.0,My blog Ranchers from Delhi
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Chanakya is using Fedora. I guess there is no installer or installation routine to configure specific Java environment variables during installation of Tomcat. At least this is true for the Linux distributions I know.

Marco
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

okay i thought he may be using windows7
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16065
    
  21

If you're running a Red Hat flavor of Linux, you can have as many JVM versions - both JDK and JRE - as you can cram onto the disk. If you install from the RPM, they're all placed in subdirectories of the /usr/java directory. The stock non-RPM install is just to explode a tarball in a suitably convenient directory. I usually find it convenient to name that directory /usr/java. You can do that for both non Red Hat and Red Hat - the RPM doesn't really do anything more than hard-code the install directory and explode into it anyway.

The "built-in" JVMs are usually more tightly bundled into to OS conventional paths, but they're still not fit for JEE use anyway, so I just ignore them and their never-to-be-sufficiently-accursed "alternatives" system, install Sun JVMs in /usr/java, and select the version I want by setting the JAVA_HOME environment variable.

If you're running multiple Tomcat instances, you have a number of possible configurations. If you want to run the exact same version of TOMCAT, this is where the distinction between CATALINA_HOME and CATALINA_BASE becomes important, because it allows you to select one Tomcat binary and launch its code in 2 distinct JVMs using 2 distinct configuration, webapp, log, and work file sets. Or, you can just make 2 separate copies of the entire Tomcat system, if you'd rather. In the case of a cluster, you normally want symmetry, so you'd point both systems' JAVA_HOME to the same jdk version, setup your CATALINA_HOME/CATALINA_BASE settings as desired, configure any necessary clustering settings, and go.


Customer surveys are for companies who didn't pay proper attention to begin with.
leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
Or, you can just make 2 separate copies of the entire Tomcat system, if you'd rather..


To Quote Tim Holloway... that would be "something you do crudely..."

Follow Tim's advice on setting up two Tomcats with distinct configurations by reading the RUNNING.TXT file that comes with your Tomcat. In there you will find info on how to run multiple instances. You will want to start and stop Tomcat using scripts and that is where you can specify multiple CATALINA_BASE values, and if you really have to, you *could* run Tomcat instances on different versions of the JVM, but that would only be for testing purposes.

Like Marco has said, when you have multiple instances of Tomcat, you really have multiple instances of a JVM.


Thanks, leo
Chanakya Gupta
Ranch Hand

Joined: May 23, 2010
Posts: 34

leo donahue wrote:
Or, you can just make 2 separate copies of the entire Tomcat system, if you'd rather..


To Quote Tim Holloway... that would be "something you do crudely..."

Follow Tim's advice on setting up two Tomcats with distinct configurations by reading the RUNNING.TXT file that comes with your Tomcat. In there you will find info on how to run multiple instances. You will want to start and stop Tomcat using scripts and that is where you can specify multiple CATALINA_BASE values, and if you really have to, you *could* run Tomcat instances on different versions of the JVM, but that would only be for testing purposes.

Like Marco has said, when you have multiple instances of Tomcat, you really have multiple instances of a JVM.



Thankyou Marco, leo, Tim, Shanky ! About the two JVMs, I got it,
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
Tim Holloway wrote:Or, you can just make 2 separate copies of the entire Tomcat system, if you'd rather.


Anyone,

The only disadvantage of this are: 1) disk space on the 2nd installation 2) maintainability, as it is more scaleable to use manageable configuations sets, than huge installations. Is this correct? Are there other disadvantages or dangers on such installations (multiple copies)?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Two instances of Tomcat on the same OS