- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud
Installing Tomcat
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.
Lab Info
Table of Contents
-
Challenge
Install Java 11 OpenJDK
You need to install the java-11-openjdk-devel package:
sudo dnf install java-11-openjdk-develOnce it's installed, check the version of Java to ensure it has installed properly and is set as the default for the system.
-
Challenge
Obtain Tomcat version 9 from the Apache Tomcat Website
Go to the webpage to get the latest version of Tomcat 9:
https://tomcat.apache.org/download-90.cgi
Go to the Binary Distributions section.
Under the Core section, right click on thetar.gz, then select Copy Link Location.Now use
wgetto download the file:wget USE-THE-URL-YOU-COPIED-EARLIER -
Challenge
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.
cd /usr/localExtract 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-EARLIERChange 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 tomcat9Add the
tomcatuser as a system account:useradd -r tomcatChange the permissions of the
tomcat9folder so thetomcatuser can use it:chown -R tomcat:tomcat /usr/local/tomcat9Create the
tomcatservice. Use an editor (like Vim) to create a file/etc/systemd/system/tomcat.service:vim /etc/systemd/system/tomcat.serviceAdd 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.targetNext we need to have the system recognize there is a new service. We can use the
daemon-reloadoption forsystemctl:systemctl daemon-reloadNow 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.serviceCheck that Tomcat works by going to your server's public IP address, on port 8080, in a web browser:
http://YOUR_SERVER_IP:8080 -
Challenge
Add an admin User for Tomcat
To add an
adminuser for Tomcat, you need to edit thetomcat-users.xmlfile:cd /usr/local/tomcat9/ vim conf/tomcat-users.xmlGo 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"/> -
Challenge
Modify Tomcat so You Can Log in Remotely
The next step is to allow access to the management web pages from the internet.
Edit the
webapps/manager/META-INF/context.xmlfile:vim webapps/manager/META-INF/context.xmlGet to the following line:
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />Change it to this:
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1 |.*" /> -
Challenge
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 tomcatGo 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
http://YOURSERVERIP: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.
About the author
Real skill practice before real-world application
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.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.