8i | 9i | 10g | 11g | 12c | 13c | 18c | 19c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux

Home » Articles » Linux » Here

Apache Tomcat 9 Installation on Linux (RHEL and clones)

Apache Tomcat 9 is not available from the standard RHEL distributions, so this article provides information about the manual installation and basic configuration of Apache Tomcat 9 on RHEL and its clones from tarballs. The tarball approach to installation is largely unchanged compared to previous tomcat versions.

Related articles.

Downloads

Download the following software. This article assumes these downloads are present in the "/tmp" directory on the server.

Installation

Create a user called "tomcat" to own the Tomcat installation. We also create a directory called "/u01" to hold all the config, and make sure that it owned by the new "tomcat" user.

# useradd tomcat
# mkdir -p /u01
# chown tomcat:tomcat /u01

Install the JDK from the tarball under the "/u01/java" directory. We unzip it to create a new directory, which includes the version number, but use a symbolic link so we can always use the same path for the JAVA_HOME environment variable, regardless of the version.

# su - tomcat
$ mkdir -p /u01/java
$ cd /u01/java
$ tar xzf /tmp/openjdk-11.0.1_linux-x64_bin.tar.gz
$ ln -s jdk-11.0.1 latest

Install Tomcat from the tarball under the "/u01/tomcat" directory. We unzip it to create a new directory, which includes the version number, but use a symbolic link so we can always use the same path for the CATALINA_HOME environment variable, regardless of the version.

$ mkdir -p /u01/tomcat
$ cd /u01/tomcat
$ tar xzf /tmp/apache-tomcat-9.0.14.tar.gz
$ ln -s apache-tomcat-9.0.14 latest

We want to separate the config from the binaries, to make future upgrades easier, so we will create a new directory to act as the CATALINA_BASE location, and seed it by copying the relevant directories to the new directory. We are using a sub-directory called "instance1" to allow for multiple instances, but that is not necessary if you only plan to have a single Tomcat instance running.

$ mkdir -p /u01/config/instance1
$ cp -r /u01/tomcat/latest/conf /u01/config/instance1/
$ cp -r /u01/tomcat/latest/logs /u01/config/instance1/
$ cp -r /u01/tomcat/latest/temp /u01/config/instance1/
$ cp -r /u01/tomcat/latest/webapps /u01/config/instance1/
$ cp -r /u01/tomcat/latest/work /u01/config/instance1/

Set the following environment variables and append them to the "/home/tomcat/.bash_profile" so they are set for subsequent logins.

export JAVA_HOME=/u01/java/latest
export CATALINA_HOME=/u01/tomcat/latest
export CATALINA_BASE=/u01/config/instance1

Start and stop Tomcat using the following scripts.

$ $CATALINA_HOME/bin/startup.sh
$ $CATALINA_HOME/bin/shutdown.sh

The Tomcat logs are written to the "$CATALINA_BASE/logs/" directory by default.

Once Tomcat is started, the following URL should be available. Configuration for the management URLs is discussed below.

http://localhost:8080/
http://localhost:8080/manager/html
http://localhost:8080/manager/status

Remember to open up the port on the firewall if you want to access the site from other servers on the network. Information about the Linux firewall is available here.

Checking the Status of Tomcat

There are several ways to check the status of the service.

$ netstat -nlp | grep 8080
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 :::8080                 :::*                    LISTEN      18751/java
$

$ ps -ef | grep tomcat
tomcat   16750     1  5 14:18 pts/1    00:00:06 /u01/java/latest/bin/java 
-java.util.logging.config.file=/u01/config/instance1/conf/logging.properties 
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 
-Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
-Dignore.endorsed.dirs= -classpath /u01/tomcat/latest/bin/bootstrap.jar:/u01/tomcat/latest/bin/tomcat-juli.jar
-Dcatalina.base=/u01/config/instance1 -Dcatalina.home=/u01 tomcat/latest -Djava.io.tmpdir=/u01/config/instance1/temp
org.apache.catalina.startup.Bootstrap start
tomcat   16919  3994  0 14:20 pts/1    00:00:00 grep --color=auto tomcat
$

$ curl -I http://localhost:8080
HTTP/1.1 200
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Sat, 15 Dec 2018 14:20:58 GMT

$

The status is also available from the HTML management page.

Configuration Files

The main locations of configuration and log information are shown below.

Release Notes        : $CATALINA_HOME
Bin Directory        : $CATALINA_HOME/bin
Config               : $CATALINA_BASE/conf
Webapps              : $CATALINA_BASE/webapps
Logs                 : $CATALINA_BASE/logs

Enabling HTML Management Access

Edit the "$CATALINA_BASE/conf/tomcat-users.xml" file, adding the following entries inside "tomcat-users" tag. Adjust the password as required.

<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="MyPassw0rd!" roles="manager-gui,admin-gui"/>

Restart Tomcat for the configuration to take effect.

$ $CATALINA_HOME/bin/shutdown.sh
$ $CATALINA_HOME/bin/startup.sh

The management application is now available from the "http://localhost:8080/manager/html" URL.

Deploying Applications

You can get a sample application WAR file to test with from "http://tomcat.apache.org/tomcat-9.0-doc/appdev/sample/".

If this is a redeployment, delete the existing deployment from the "$CATALINA_HOME/webapps" directory.

# rm -Rf $CATALINA_BASE/webapps/sample

Place the "sample.war" file in the "$CATALINA_HOME/webapps" directory and Tomcat with automatically deploy it. You will see a "sample" directory appear.

You don't need to stop and start Tomcat for this to work, but you can if you want.

$ $CATALINA_HOME/bin/shutdown.sh
$ $CATALINA_HOME/bin/startup.sh

Java and Tomcat Upgrades

To upgrade, we just need to stop Tomcat, unzip the new software, alter the symbolic links and start Tomcat again.

In the following example shows how you would do this, but clearly you would have to alter the version numbers.

$CATALINA_HOME/bin/shutdown.sh

cd /u01/java
tar xzf /tmp/openjdk-11.0.1_linux-x64_bin.tar.gz
rm latest
ln -s jdk-11.0.1 latest

cd /u01/tomcat
tar xzf /tmp/apache-tomcat-9.0.14.tar.gz
rm latest
ln -s apache-tomcat-9.0.14 latest

$CATALINA_HOME/bin/startup.sh

# Tail the log file to watch the startup.
tail -f $CATALINA_BASE/logs/catalina.out

For more information see:

Hope this helps. Regards Tim...

Back to the Top.