search
top

Install Tomcat 7 and Java 1.7 on CentOS 6 RHEL 6

In this post we will cover how to install the Apache Tomcat 7 and jre 1.7 on CentOS 6 and RHEL 6. This process doesn’t use the rpm’s from the Redhat repositories, but uses the latest tar balls from Apache and Oracle. We will also be using service accounts to control Tomcat and its processes.

Download latest Tomcat from http://tomcat.apache.org/download-70.cgi. Version 7.0.40 is the curent version at the time of this post.
Download the latest Java 1.7 jdk from http://www.oracle.com/technetwork/java/javase/downloads/index.html, click on the JDK download buton. You will want jdk-7u21-linux-x64.tar.gz tarball.
Copy the downloaded tarballs to /tmp directory on your server.

Change directory to /opt or the directory of your choice on the server. I am using /opt for this post to contain Java and Tomcat.

$ cd /opt

Make the tomcat directory and change to it.

$ mkdir tomcat
$ cd tomcat

This step is optional to create individual instances by name for tomcat. Doing this allows you to run multiple instances of tomcat on a server. For this example tomcat-inst1 is what we will be using.

$ mkdir tomcat-inst1
$ cd tomcat-inst1

untar Tomcat in the instance you will be running.

$ tar -xvzf /tmp/apache-tomcat-7.0.40.tar.gz

Create a symlink called tomcat-current. This will allow you to untar newer versions of Tomcat and juwst update the symlink.

$ ln -sf apache-tomcat-7.0.40 tomcat-current

Create tomcat service account and set the UID to 520

$ useradd -u 520 -c “Tomcat Service Account” -d /opt/tomcat -m -s /bin/bash tomcat

 

Change ownership of the tomcat directory to the tomcat user.

Create an init.d script to start the Tomcat instance at reboot. There is not one available when using Apache supplied tarball install. Copy the below code and save as tomcat-inst1 in /etc/init.d directory, modify the instance name variable.

Make the following changes
# Source function library.
. /etc/rc.d/init.d/functions

INSTANCE=tomcat-inst1
export INSTANCE
CATALINA_HOME=/app/tomcat/${INSTANCE}/tomcat-current

Set init script to run at startup.

Setup Java jdk 1.7

Untar the tarball

Create the symlink

Create setenv.sh in /opt/tomcat/tomcat-inst1/tomcat-current/bin/ . In this exaple there is a ENV_LEVEL which you can omit the two lines or use them. This is for maintaining different developement levels set to correct environment (DEV, INT, CERT, PROD) if you want to use them.

Modify tomcat-users.xml to set password and roles access.

Make a backup of the current file.

Create a new file with the following contents and set the passwords to your liking.

Now we can start Tomcat up and should be working.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

top