Tomcat installation on Red Hat 7 in an Enterprise environment

First things first. For security reasons I do not like my developers fooling around in the “usr” directory so I totally disagree with the way Red Hat installs Tomcat 7. I like my Tomcat binaries and web apps in the “opt” directory or in a directory mount for an external disk array. I do like the startup scripts from the Red Hat installation because it adds it as a service and makes everything nice and neat on the server.

Another thing I have ran into with developers, they do not like openJDK for what ever reason. So first we need to replace the openJDK with Oracle java. To do this we need add the Oracle repositories to our Red Hat installation.

subscription-manager repos --enable rhel-7-server-thirdparty-oracle-java-rpms

Now we need to install Oracle java. My developer are using 7.

yum install java-1.7.0-oracle*

Now we need to Red Hat which version java to use.

alternatives --config java

This will bring up a menu of the 2 versions of java running. Select the Oracle java that is listed. Now check that the right version is working.

java -version

Lets install the Red Hat version of tomcat because it installs some files that are helpful and registers our startup services.

yum install tomcat*

Developers are very whiny when it comes to specific versions of tomcat servers. I don’t know why but its not my job to know. This is another reason to install tomcat this way, you are not locked to a specific version because of the Red Hat installation. I downloaded the version they want from Apache’s web site and extracted it to the “opt” directory. For this “how to” I am using 7.0.52.

Now we have our binaries and files where we want them. Lets configure our startup and configuration files. The main configuration file for startup is located in “/etc/sysconfig/tomcat”. I use “nano” because its installed by default into Red Hat now. I know there is a lot “vi” people but I am a “nano” person. I know how to use “vi” proficiently because I am responsible for Solaris systems and many many other systems. When I can get away with “nano” its a relief.

nano -w /etc/sysconfig/tomcat

This file has some lines to change. I am not going to show the whole file just lines that need to changed.

# Where your java installation lives
#JAVA_HOME="/usr/lib/jvm/java"

# Where your tomcat installation lives
#CATALINA_BASE="/usr/share/tomcat"
#CATALINA_HOME="/usr/share/tomcat"
#JASPER_HOME="/usr/share/tomcat"
#CATALINA_TMPDIR="/var/cache/tomcat/temp"

The “JAVA_HOME” variable I would leave as is but if you have a specific version of java that you want tomcat to use and its not in the default location you will need to change this. The “CATALINA_BASE”, “CATALINA_HOME”, are going to the base directory of your tomcat installation. The “JASPER_HOME” variable is if you have Jasper Reports installed. That is for another tutorial. The “CATALINA_TMPDIR” is perfect for where its pointing because it will get cleaned out by the tmp helper application running on the server. I have been asked in the past to point it else where by the developers. Here is what mine looks like now.

# Where your java installation lives
#JAVA_HOME="/usr/lib/jvm/java"

# Where your tomcat installation lives
CATALINA_BASE="/opt/apache-tomcat-7.0.52"
CATALINA_HOME="/opt/apache-tomcat-7.0.52"
#JASPER_HOME="/usr/share/tomcat"
#CATALINA_TMPDIR="/var/cache/tomcat/temp"

This configures our startup script for Tomcat. Now we need to tell Tomcat where its installation is. In “/etc/tomcat/tomcat.conf” there is only one line I had change but look over it to see if you have anything that needs changed.

CATALINA_HOME="/usr/share/tomcat"

To

CATALINA_HOME="/opt/apache-tomcat-7.0.52"

Thats it. Now you can “systemctl enable tomcat” to enable the service on boot. Then “systemctl start tomcat” to start the service.

There are tons of other configuration for the tomcat server