Lab 1: Installing Tomcat
Objective: In this lab, you will install Tomcat as a service on Ubuntu.
-
Login to your VM as the tomcat user. The password is simply password.
-
Keep track of your IP address. You will need it later in this lab:
-
Notice there is a Tomcat distribution already downloaded in the /home/tomcat directory. Use tar to unzip and extract the Tomcat distribution file.
-
It is a good practice to use a symbolic link for starting and stopping Tomcat. This makes it easier to upgrade to a different version in the future. Create a symbolic link for the Tomcat folder:
sudo ln -s /home/tomcat/apache-tomcat-9.0.0.M19 /opt/tomcat-latest
The sudo password for tomcat is password.
-
You now have /opt/tomcat-latest linked to your apache-tomcat-9.x install directory, but root created the link so you need to chown the link to tomcat:
sudo chown -R tomcat:tomcat /opt/tomcat-latest
-
In this step, you will configure Tomcat as a service. There is a file already created for you that is designed for starting, stopping and restarting Tomcat as a service. Copy the file /home/tomcat/Lab_01/tomcat into /etc/init.d:
cp /home/tomcat/Lab_01/tomcat /etc/init.d/
The file looks like:
# Service file for Tomcat
#
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-i386/
case $1 in
start)
sh /opt/tomcat-latest/bin/startup.sh
;;
stop)
sh /opt/tomcat-latest/bin/shutdown.sh
;;
restart)
sh /opt/tomcat-latest/bin/shutdown.sh
sh /opt/tomcat-latest/bin/startup.sh
;;
esac
exit 0
-
chmod the tomcat init file to 755:
sudo chmod 755 /etc/init.d/tomcat
-
You are now ready to start Tomcat as a service on your Ubuntu instance. Run the following command:
service tomcat start
-
Verify that Tomcat is running by opening your Web browser and pointing it to your Tomcat instance. The URL will look like http://your_vm_ip:8080/ using the IP address from that you noted in step 2 of this lab. You should see the homepage of your Tomcat instance:
-
Stop your Tomcat instance:
service tomcat stop
-
Setup Tomcat to start automatically when your VM starts by creating symbolic links to your init.d/tomcat script in the appropriate Ubuntu runlevel folders. Let's configure rc1 and rc2:
sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat
-
Reboot your VM:
sudo reboot
-
Tomcat should be running. View your running processes to verify:
ps -eaf | grep tomcat
Also, go back to your Web browser and reload the Tomcat home page to verify your startup script is working properly.
Summary: You now have installed Tomcat and configured your server to run Tomcat as a service on startup.