How to run two instances of Tomcat on your machine

Tags: tomcat, java, linux,

Added: 2009-08-29T00:00

How to run two instances of Tomcat on your machine

I decided I wanted two Tomcats running on the same box, one for "live", and one for "dev".
I'm going to put these notes here, for me, so I can do it again if I stuff things up, and for other people. You can cut and paste these commands blindly, or do them one at a time.
I did this on a Ubuntu "Jaunty" server, with 6.0.18-0ubuntu6.1 installed. Your mileage may vary if you have a different distro/version.
Decisions I made:


  • I decided to call my dev one tomcat6dev.

  • I chose to run it as the same user as the "live" one (tomcat6) - you can use another user if you like.

  • I wanted to symlink as much stuff as possible, so that updates would apply to them both

cd /etc/
cp tomcat6/ tomcat6dev/ -Rfv
cd tomcat6dev/

rm catalina.properties 
ln -s ../tomcat6/catalina.properties 

rm context.xml 
ln -s ../tomcat6/context.xml 

rm policy.d/ -Rfv
ln -s ../tomcat6/policy.d/

rm logging.properties 
ln -s ../tomcat6/logging.properties 

rm tomcat-users.xml 
ln -s ../tomcat6/tomcat-users.xml 

rm web.xml 
ln -s ../tomcat6/web.xml 

vim server.xml

I can't script this bit for you. I changed all the ports from 8xxx to 9xxx.
cd /etc/init.d/
cp tomcat6 tomcat6dev
vim tomcat6dev

Change the "NAME" statement to tomcat6dev
cd /usr/share/
mkdir tomcat6dev
cd tomcat6dev/
ln -s ../tomcat6/bin
ln -s ../tomcat6/lib
mkdir webapps

cd /var/lib
mkdir tomcat6dev
cd tomcat6dev/
ln -s ../../log/tomcat6dev logs
ln -s /etc/tomcat6dev conf
ln -s ../../cache/tomcat6dev work
mkdir webapps

cd /var/cache/
mkdir tomcat6dev
cd tomcat6
cd ../../log/
mkdir tomcat6dev

Now I have to sort out the permissions. I wish I'd used cp -Rafv earlier.
cd /var/log
chown tomcat6:adm tomcat6dev
chmod 750 tomcat6dev

cd /var/cache/
chown tomcat6:adm tomcat6dev
chmod 750 tomcat6dev

cd /etc/
vim tomcat6dev/Catalina/localhost/manager.xml
# Did I change anything here?

cd /usr/share/
ln -s tomcat6-admin/ tomcat6dev-admin

cd /etc/tomcat6dev/Catalina/localhost/
rm *.xml 
cd ..
cd ..
chgrp tomcat6 Catalina/
chmod 775 Catalina/
chmod 775 Catalina/localhost/
chgrp tomcat6 Catalina/localhost/
cd /var/
chgrp tomcat6 lib/tomcat6dev/webapps/
chmod 775 lib/tomcat6dev/webapps/
Now create a couple of workers, live and dev perhaps, and sort them out.
vim /etc/apache2/workers.properties
And restart apache.
/etc/init.d/apache2 restart
Finally, you get to start your tomcat6dev, and see what happens.
/etc/init.d/tomcat6dev start
Then browse to http://your-ip:9080/manager/html and see what happens.
Add a comment

Your IP:
Please enter 3997647 here: