Running multiple Tomcat instances on Debian Lenny
(Or any other flavor of Linux)
Multiple Tomcat instances on Debian Linux? Yup, it can be done with a little bit of configuration magic. The below example assumes that you have multiple IPs already configured on your server and want to run each Tomcat instance on a single unique IP over port 80.
- Don't install a Tomcat package via apt-get or whatever. Besides the packages having a long list of problems with anything but the most trivial setup, it does not help you get multiple instances up and running. Instead download the tar files and unpack into instance specific directories. I personally run each instance with its own user in said user's home directory. E.g.:
/home/tomcat0 /home/tomcat0/apache-tomcat-7.0.0 /home/tomcat1 /home/tomcat1/apache-tomcat-7.0.0 /home/tomcat2 /home/tomcat2/apache-tomcat-7.0.0 - In
conf/server.xml, configure the Server's port attribute to an instance specific value. I use a simple equation: the last for bytes of the IP address plue 8000. E.g.: 10.20.30.40 would use port 8040. The port is used by thebin/shutdown.shscript to signal Tomcat to shutdown. It only listens to the localhost and not the specific IP configured elsewhere.<Server port="8058" shutdown="SHUTDOWN"/> - Also in
conf/server.xmlis the Connector, which will need configuring. In this example we have the default HTTP Connector. You'll want a unique IP for each instance, which is configured with the address atribute. And if doing port redirection then set the proxyPort attribute too. (See bottom of post for more on this.)<Connector port="8080" proxyPort="80" address="10.0.0.1" protocol="HTTP/1.1" redirectPort="8443" />
I've not bothered with setting up instance specific init.d scripts. For better and worse, I run my instances with manual start up and shutdown. Why? We have 'hot stand-by' servers and prefer our fail-over process to be manually instigated. If anyone one there writes some instance specific scripts I would be glad to post them here.
Regardless, the above configuration will get you up and running with multiple Tomcats on a single box!
(If you are reading this, then you may very well be interested in Port redirection for multiple Tomcat instances on linux 2.6 with iptables too.)