Mar
21
2011

Tomcat : multiple instances on the same server

For those hoping that the title of this post actually contains the secrets of the Tomcat server… well… it doesn’t. I’ll just explain what settings to change to be able to deploy on a single machine, multiple  instances of the web server.

First …

How is Tomcat organized ?

Tomcat can be decomposed into two parts, two folders that you put the path in the two corresponding environment variables.

  • CATALINA_HOME : the folder that contains the information common to all instances
    • bin : Tomcat executables
    • lib : libraries used by Tomcat
  • CATALINA_BASE points to the folder that contains information specific to each instance
    • conf : configuration files of the instance
    • temp : the temporary folder of the JVM (java.io.tmpdir)
    • webapps : web applications deployed
    • work : temporary work files used by the server
    • logs : the server and applications logs

To deploy multiple instances of Tomcat on one machine, we must specify for each instance a folder CATALINA_BASE and a folder CATALINA_HOME (this one  may be common to all instances)

In a typical installation, CATALINE_HOME CATALINE_BASE are the same

How to configure my instances ?

Now that we have seen how  Tomcat is organized, let’s configure our instances. For the purpose of this example, we will say we want 3.

I’ll create the 4 following folder (1 CATALINA_HOME and 3 CATALINA_BASE) that contain the default files for a tomcat installation organized as explained previously

Now, I’ll edit the configuration files for each instance to associate different ports for each one. To do this, edit the server.xml file located in the conf folder.

First change the listening port of the SHUTDOWN command

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

Personally, I choose ports 8001, 8002 and 8003.

Then, for each connector in server.xml, you must define a port number for each instance. By default, the Tomcat configuration contains two connectors, HTTP and AJP.

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3"
           redirectPort="8443" />

I choose 8080, 8081 and 8082 for HTTP and  8009, 8010 and 8011 for AJP . The “redirectPort” is the port where requests will be redirected for all queries that require SSL transport. If you use it and you have also defined the corresponding SSLEnabled connector, you must also consider changing this port.

Now it should work, shouldn’t it ? A small thing left, configuring CATALINA_BASE for each instance.

Before calling Tomcat startup script located in the bin CATALINA_HOME, just export in the environment variable CATALINA_BASE, the instance folder you want to start (do the same to stop it).

Which gives on a Unix system


export CATALINA_BASE=Path/To/My/Instance/1
$CATALINA_HOME/bin/startup.sh

This has the effect to start an instance of Tomcat using the configuration located in  Path/To/My/Instance/1

Then repeats this process for each instance you want to start and we can (should?) obviously put it all in scripts to automate it.
To stop an instance, the principle is the same, except that instead of calling the startup.sh script, we’ll call this time shutdown.sh

And now, our three Tomcat servers are running concurrently on the same machine …And besides, we saved space :)

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image

Language

  • Français
  • English

Tag cloud