Install/Setup and Configure Tomcat on CentOS/RHEL/Amazon Linux

This article will guide you through the installation and configuration steps of Tomcat 8 on your CentOS/RHEL/Amazon Linux

The procedure mentioned in this tutorial is tested on:

OS Amazon Linux
Oracle Java 1.8.0_31
Tomcat 8.0.18

Apache Tomcat is an open-source web server and servlet container from the Apache Software Foundation (ASF). Tomcat implements several Java EE specifications including Java Servlet, JavaServer Pages (JSP), Java EL, and WebSocket, and provides a “pure Java” HTTP web server environment for Java code to run in.
Tomcat can be used as either a standalone product with its own internal Web server or together with other Web servers, including Apache and Microsoft Internet Information Server (IIS). Tomcat requires a Java Runtime Enterprise Environment that conforms to JRE 1.1 or later.

  • Tomcat 8 supports Java Servlet 3.1
  • Tomcat 8 supports JavaServer Pages 2.3
  • Tomcat 8 supports Java Unified Expression Language 3.0
  • Tomcat 8 supports Java WebSocket 1.0

(I) Prerequisite
Note: Before installing we need to update our system using “yum update“.

# yum update -y

(a) Installing Oracle Java using the link.

(II) Installing Tomcat 8
(a) Download the latest Tomcat 8 (8.0.18) package from Apache Site using “wget” command:

# wget -P /usr/local/src/

(b) Now let’s install Tomcat package once it is downloaded, using “tar” command:

# tar -C /opt -xzf /usr/local/src/apache-tomcat-8.0.18.tar.gz

(c) Let’s create a user and assign ownership to that user that will run the Tomcat server:

# useradd -r tomcat --shell /bin/false
# ln -s /opt/apache-tomcat-8.0.18 /opt/tomcat
# chown -hR tomcat: /opt/tomcat /opt/apache-tomcat-8.0.18

(III) Starting Tomcat Service
Download the tomcat startup script and save to /etc/init.d/ directory.

# wget -O /etc/init.d/tomcat

Make the script executable using “chmod” command:

# chmod +x /etc/init.d/tomcat

Activate the Tomcat service at system startup using “chkconfig” command:

# chkconfig tomcat on

Start the Tomcat service using “service” command:

# service tomcat start

Sample Output:
Starting tomcat
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr/java/default
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.

(IV) Verifying Tomcat
Check the tomcat process is running using the process status command:

# ps -ef | grep -i tomcat

Sample Output:
tomcat    7027     1  7 18:45 pts/0    00:00:03 /usr/java/default/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/ -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC -XX:MaxPermSize=128m -Xms512m -Xmx512m -Djava.endorsed.dirs=/opt/tomcat/endorsed -classpath /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat -Dcatalina.home=/opt/tomcat org.apache.catalina.startup.Bootstrap start

Check for port used by tomcat process using the netstat or lsof command:

# netstat -planet | grep -i java

Sample Output:
tcp        0      0 :::8080                     :::*                        LISTEN      498        12492      7027/java
tcp        0      0 ::ffff:       :::*                        LISTEN      498        12506      7027/java
tcp        0      0 :::8009                     :::*                        LISTEN      498        12496      7027/java

# lsof -i | grep -i java

Sample Output:
java     7027   tomcat   49u  IPv6  12492      0t0  TCP *:webcache (LISTEN)
java     7027   tomcat   54u  IPv6  12496      0t0  TCP *:8009 (LISTEN)
java     7027   tomcat   72u  IPv6  12506      0t0  TCP localhost:mxi (LISTEN)

In your favorite browser open default WebUI Page of Tomcat using IP or FQDN (http://SERVER-FQDN-OR-IP:8080)

(V) Setup User Accounts
Finally we need to create user accounts to secure and access admin/manager pages. Edit conf/tomcat-users.xml file in your editor and paste inside <tomcat-users> </tomcat-users> tags.

<role rolename="manager-gui" />
<user username="manager" password="YOUR_PASSWORD" roles="manager-gui" />

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

Please check the red arrow pointing to Server Status, Manager App, Host Manager link.


Related Posts:

Installing and Configuring Oracle Java on CentOS/RHEL/Amazon Linux