- A Cloud Guru
Welcome to this hands-on lab for installing Tomcat 9 onto Red Hat Enterprise 8. Apache's Tomcat is a Java based application platform built around deploying and managing Java Web Applications. Tomcat is cross-platform, working on anything that supports Java, but this hands-on lab focuses on a Red Hat 8 deployment. In it we will configure the system and install Tomcat version 9. Once we have Tomcat installed, we will configure it with a user and then configure it so we can access the management web console via the internet.
Table of Contents
Install Java 11 OpenJDK
You need to install the java-11-openjdk-devel package:
sudo dnf install java-11-openjdk-devel
Once it's installed, check the version of Java to ensure it has installed properly and is set as the default for the system.
Obtain Tomcat version 9 from the Apache Tomcat Website
Go to the webpage to get the latest version of Tomcat 9:
Go to the Binary Distributions section.
Under the Core section, right click on the
tar.gz, then select Copy Link Location.
wgetto download the file:
Install and Configure Tomcat, Create the User and Service, Then Start It and Ensure It Starts on a System Reboot
You need to expand the compressed Tomcat files into the location it will be put.
Change to the
rootuser (or add 'sudo' at the beginning of the commands that follow)
sudo su -
Change to the location we will use for the tomcat files.
Extract the downloaded file to the current location. Note: replace THE-TOMCAT-FILE-YOU-COPIED-EARLIER with the correct file that was downloaded.
tar -xvf /home/cloud_user/THE-TOMCAT-FILE-YOU-COPIED-COPIED-EARLIER
Change the name of the Tomcat folder to
tomcat9. Note the version you get may be newer than this one. Change the name as needed:
mv apache-tomcat-9.0.31 tomcat9
tomcatuser as a system account:
useradd -r tomcat
Change the permissions of the
tomcat9folder so the
tomcatuser can use it:
chown -R tomcat:tomcat /usr/local/tomcat9
tomcatservice. Use an editor (like Vim) to create a file
Add the following contents (and note that if you copy and paste whats below, ensure the lines in your file do not have leading spaces):
[Unit] Description=Apache Tomcat After=syslog.target network.target [Service] Type=forking User=tomcat Group=tomcat Environment=CATALINA_PID=/usr/local/tomcat9/temp/tomcat.pid Environment=CATALINA_HOME=/usr/local/tomcat9 Environment=CATALINA_BASE=/usr/local/tomcat9 ExecStart=/usr/local/tomcat9/bin/catalina.sh start ExecStop=/usr/local/tomcat9/bin/catalina.sh stop RestartSec=12 Restart=always [Install] WantedBy=multi-user.target
Next we need to have the system recognize there is a new service. We can use the
Now we can start the service, set it to restart on system boot, and check if it's currently running:
systemctl start tomcat.service systemctl enable tomcat.service systemctl status tomcat.service
Check that Tomcat works by going to your server's public IP address, on port 8080, in a web browser:
Add an admin User for Tomcat
To add an
adminuser for Tomcat, you need to edit the
cd /usr/local/tomcat9/ vim conf/tomcat-users.xml
Go to the bottom of the file, and put the following just before the
</tomcat-users>end block. Don't forget to change the YOURPASSWORDHERE to be your own password, whatever you like:
<role rolename="admin-gui,manager-gui"/> <user username="admin" password="YOURPASSWORDHERE" roles="admin-gui,manager-gui"/>
Modify Tomcat so You Can Log in Remotely
The next step is to allow access to the management web pages from the internet.
Get to the following line:
Change it to this:
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1 |.*" />
Restart Tomcat and Check Remote Connectivity
The next task is to restart the Tomcat and ensure it is accessible, then try logging in:
systemctl restart tomcat
Go to the public IP address of the lab server and test out logging in via the port 8080.
Check that Tomcat works by going to your server's web page on port 8080
Log in with the username and password you completed on Step 5: Add an admin User for Tomcat
You should be able to log in and manage the Tomcat installation.
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.