Sep 172007

I’m spent about 6 hours total working on getting multiple instance of Tomcat to run on Ubuntu and finally wrote some scripts that I’d like to share with folks. These scripts do the following:

1. Setup the box to host multiple instances (JVMs) running tomcat

This process cleans the old layout and sets up a new layout that allows for multiple instances. This includes a number of “instances” directories in /var/lib/tomcat5.5, /etc/defaults/tomat5.5 (a new directory) and /var/log/tomcat5.5.

2. Create new instances

This allows you to setup a new instance quickly. It creates all the necessary directories and also installs the new instance into the init scripts an run levels.

Things the scripts don’t do:

– Setup multiple mod_jk configurations and apache virtual hosts
– Any SSL or security management

Here’s how to use the scripts:

1. First make sure you have Java and Tomcat installed!

2. Grab ALL of the scripts and place them in some directory (anywhere is fine)

3. Run the script as root from the directory you put it in

4. Run the script to create a new instance

5. Configure the new server by editing the files in /var/lib/tomcat5.5/instances/<instance-name> (mainly conf/server.xml)

6. Make sure each instance has a unique port for everything including the AJP, all listeners and the container

7. Fire it up!

8. Check the logs in /var/log/tomcat5.5/instances/<instance-name>/catalina.out

Due to security considerations, I’ve included the scripts inline. Any comments are welcome:

  17 Responses to “Multiple Tomcat instances on Ubuntu”

  1. Great scripts, thanks. Found one small error in

    # Clean up defaults for the template script
    cd /etc/defaults/

    Should be /etc/default.

    . m

  2. Nice catch. Updated the post to include your fix.

  3. These are great. I would have had to spend more than 6 hours creating the same thing.

    I only had issues with copying from the web. Maybe its just me but I get bad “, ‘, and ` characters. I also get line breaks so a continuation character ( \ ) would be useful. Downloadable scripts could fix these issues but I’m not concerned with the security issues.

  4. Dear Sir,

    That’s good you have access two instances on same machine of tomcat, but you access them on Linux or I think SUSE, but I have problem to access two liferay tomcat on same machine, I have changed port & java_home in server.xml & catalina.bat. Should I need to change another files too for it.

  5. Nice scripts, thanks :)
    Could you provide a download link though? As mentioned your blog is adding bad characters and stripping the line continuation characters.

  6. I created a Google code project and open sourced these scripts. Figured it was easier this way. Here’s the place for these scripts:

    You can check them out from SubVersion or browse them via the web.

  7. Are these scripts accurate as written for ubuntu 8.x and tomcat5.5?


  8. Jack,

    I’d recommend checking out the latest work I’ve done on Tomcat on Linux. I posted a DEB for running multiple instances of Tomcat 6 on Linux and it completely replaces the standard Tomcat. It also cleans up many of the messes that Debian has created with their package and is a 100% valid Tomcat installation.

    Here’s the post from the Ubuntu Forums on it:

    I’ll put up another blog post here about it as well.

  9. Hi Brian,

    Your scripts are using the older JK workers style to connect apache to tomcat. With Apache 2.2, you can also use the (easier) mod_proxy_ajp.
    Is it a good suggestion if you update your scripts to this?


  10. Marcel,

    If you want to join the project I’ve setup, it is located here:

    That project can create DEB packages and contains some more advanced scripts. Eventually I’d like to start publishing the DEBs into a valid APT repo. These scripts are also using Tomcat 6.0.x and can certainly use Apache 2.2 and mod_proxy_ajp.

    Let me know if you want to help on that project.

  11. Hi Brain,

    I can see if i can help you with that :)… though my DEB knowledge is newby!

    Some ideas:
    – would be great to have the possibility to turn a manual instance into a init.d’ed instance and vice versa
    – how about a t6eninstance and t6disinstance command (like a2ensite and a2dissite) which places symlinks from instances-available to a instances-enabled folder. That way, init.d/tomcat6instances can take one argument (stop/start/restart) and does that on all instances.. or takes two arguments, where 2nd is the instance name from the dir “instances-enabled”

  12. Perhaps. The main difference here is that Apache is a single process where the way I have Tomcat setup is that each instance is a separate process. This was intentional in order to prevent one webapp from crashing others.

    Any solution would need the ability to control single instances in cases of failures where a single instance needs to be restarted.

  13. Nice work!!!
    And this makes me think!!!
    What if we want to run two different versions of tomcat on the same server, say 5x and 6x.
    How could we manage that in case we have two different applications that one can run only with 5x and the other only with 6x?

  14. That should work fine. You just need to ensure you can install both the 5.5. and 6.0 packages at the same time. This should be possible on most Linux varieties.

  15. It’s the best time to make a few plans for the long run and it is time to be happy. I have read this submit and if I could I desire to suggest you some attention-grabbing issues or advice. Perhaps you can write subsequent articles relating to this article. I desire to read more issues approximately it!

  16. Pretty section of content. I simply stumbled upon your website and in accession capital to say that I acquire in fact enjoyed account your weblog posts. Any way I will be subscribing in your feeds or even I achievement you access constantly fast.

  17. I have written a Java based portable utility for automating the above steps for creating multiple instances. Since Java is platform independent, this utility works on all operating systems

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">



This site uses Akismet to reduce spam. Learn how your comment data is processed.