Add another instance of Tomcat, on Ubuntu

Add another instance of Tomcat, on Ubuntu

On my Ubuntu server (13.10, Saucy), I have been trying to set up Geonetwork and Geoserver, servlet applications that I wanted to run under the Tomcat application server. I had a conflict with some shared libraries loaded to Tomcat, and I managed to solve it by installing a second instance of Tomcat, here is how I did it. The shared libraries were from Railo, the application server that powers this website, which I didn't want to remove. I understand it as there is added funcationality in the upcoming Tomcat 8 where one can exclude some shared libraries on a per context basis, but it is still in beta, and I am not keen on running it on my production server at this time.

My starting point was this website, with some help from some other links, including some posts on StackOverflow.

First install tomcat7-users, which adds some handy scripts to create a new instance:

sudo apt-get install tomcat7-user

Then set up the new folder for the Tomcat7 instance:

cd /opt
sudo tomcat7-instance-create -p 8081 -c 8006 tomcat7_geo
# I am setting up this instance under /opt/tomcat7_geo

sudo chown tomcat7 tomcat7_geo -R
# tomcat7 should own this folder

There are apparently some files that are still missing from this new instance, and they need to be copied/set up:

cd /opt/tomcat7_geo
sudo cp /etc/tomcat7/policy.d conf/policy.d

To get it set up as a service:

cd /etc/init.d
sudo cp tomcat7 tomcat7_geo
sudo vim tomcat7_geo

Now locate the following lines and update:

DESC="Tomcat servlet engine (geo)"

To enable the service setup:

sudo update-rc.d tomcat7_geo defaults 90

Now you can start/stop it using the service command:

sudo service tomcat7_geo start

To test it, you might want to add the examples/manager to the localhost host/context.

My next step is to set up this new instance with mod_jk and thus connect it to Apache2. I edit the file, and add a new worker to the worker.list, and define parameters for it (port 8010 in my case), and add that as a connector to /opt/tomcat7_geo/conf/server.xml (<Connector port="8010" protocol="AJP/1.3" redirectPort="8444" />)

In httpd.conf I next add: JkMount /* worker2

Restart apache and the new tomcat instance, and you should be good to go!