Tomcat with a segregated configuration

Here’s a step-by-step guide to deploy Tomcat (6 or 7). I’ll use 7 for the rest of this guide but the procedure is the same regardless of the version. I try to avoid modifying the Tomcat install itself once deployed, so I redirect the configuration to an alternate location. This makes upgrades very simple and keeps all the important pieces in one place.

Start by cloning my github tomcat repo to get the files you need:

git clone git://

Among the files in the repo, and, are intended to make things easier by setting some environment variables. Copy both files into /etc/profile.d/

# cp /etc/profile.d/
# cp /etc/profile.d/

In order for them to take effect, log out and back in. You should now see a TOMCAT_HOME, CATALINA_HOME and JAVA_HOME set. If JAVA_HOME is not set, you might not have java installed. You can use the openjdk version available with most RHEL-distros. If you want to use the Sun (Oracle) version, the java.profile should be able to find that one once it’s installed.

Let’s deploy Tomcat 7 on the host:
1. Download the tomcat source tarball from
2. Untar the tarball (usually best to do this in your home folder)

# tar -zxvf apache-tomcat-7.0.28

3. Move the resulting folder into /usr/local

# mv apache-tomcat-7.0.28 /usr/local

4. Navigate to /usr/local
5. Create a symlink to simplify the path

# ln -s /usr/local/apache-tomcat-7.0.28 tomcat

6. Change the owner and group for this install to root:root

# chown -R root:root /usr/local/apache-tomcat-7.0.28

Now we need to setup the segregated instance:
1. Create the alternate location tree:

# mkdir -p /var/tomcat/{bin,conf,shared,temp,webapps,work}
# mkdir -p /var/tomcat/shared/{classes,lib}
# mkdir -p /var/log/tomcat

2. Stage the critical files to run this redirected instance (using /var/tomcat):

# cp $TOMCAT_HOME/conf/ /var/tomcat/conf/
# cp $TOMCAT_HOME/conf/ /var/tomcat/conf/
# cp $TOMCAT_HOME/conf/server.xml /var/tomcat/conf/
# cp $TOMCAT_HOME/conf/tomcat-users.xml /var/tomcat/conf/
# cp $TOMCAT_HOME/conf/web.xml /var/tomcat/conf/

3. Navigate to /var/tomcat
4. Symlink the logs folder into the redirected instance:

# ln -s /var/log/tomcat logs

5. Determine the user your tomcat install should run as (Ex: tomcat).
6. Change the owner of /var/log/tomcat and /var/tomcat to that user (otherwise tomcat will not start).

# chown tomcat:tomcat /var/log/tomcat
# chown -R tomcat:tomcat /var/tomcat

7. Set file and folder permissions for the redirected instance:

# find /var/tomcat -type d -exec chmod 775 {} \;
# find /var/tomcat -type f -exec chmod 664 {} \;

8. Copy the init script from my git repo.

# cp tomcat.init /etc/init.d/tomcat

9. Change the owner and file permissions:

# chown root:root /etc/init.d/tomcat
# chmod 755 /etc/init.d/tomcat

10. To force the installed tomcat to use our redirected instance, use the from my repo, copy it into /usr/local/tomcat/bin

# cp /usr/local/tomcat/bin

11. Modify the as necessary.
12. Start tomcat:

# /etc/init.d/tomcat start

13. Check the folder /var/log/tomcat for catalina.out (among other files).

If there is no catalina.out in /var/log/tomcat, check folder permissions and ownership in /var/tomcat as well as /var/log/tomcat.

Look for my post on adding the Tomcat native libraries for enhanced performance here.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s