There are a number of posts on how to do this. I have created this post mostly for my own records so I know I will continue to have a record of what I have done.
Setup
Ensure you have at least JDK 8, I have the RPM “java-1.8.0-openjdk.x86_64” installed by this point.
Create a system user account to run tomcat:
useradd -r tomcat –shell /bin/false
Download the Tomcat 9 zip file, in my case this was “apache-tomcat-9.0.22.zip” which I downloaded to “/var/tmp” and then extract it and set permissions:
cd /var/tmp
unzip apache-tomcat-9.0.22.zip -d /opt
mv /opt/apache-tomcat-9.0.22 /opt/tomcat9
chown -R tomcat.tomcat /opt/tomcat9
Now create a service file:
/etc/systemd/system/tomcat.service
For me this looked like:
[Unit] Description=Apache Tomcat 9 After=syslog.target network.target [Service] User=tomcat Group=tomcat Type=forking Environment=CATALINA_PID=/opt/tomcat9/tomcat.pid Environment=CATALINA_HOME=/opt/tomcat9 Environment=CATALINA_BASE=/opt/tomcat9 ExecStart=/opt/tomcat9/bin/startup.sh ExecStop=/opt/tomcat9/bin/shutdown.sh Restart=on-failure [Install] WantedBy=multi-user.target
Now set the correct permissions for the Tomcat startup script, enable the service and finally start the service:
cd /opt/tomcat9/bin
chmod 774 *.sh
systemctl enable tomcat.service
systemctl start tomcat.service
At this point Tomcat is running and you should be able to access it on port 8080 so:
http://centos7-base:8080/
References
Rose Hosting: Install Tomcat 9 on CentOS 7
https://www.rosehosting.com/blog/install-tomcat-9-on-centos-7/
Red Hat: Creating and Modifying systemd Unit Files
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/sect-managing_services_with_systemd-unit_files