System Update and Package Installation
Update Package List
# apt update
Upgrade All Packages
# apt upgrade -y
Java Installation
Install OpenJDK 11
# apt install openjdk-11-jdk
Verify Java Installation
# java -version
Create Tomcat User
For security reasons, create a new user for the Tomcat server.
Create Tomcat Group
# groupadd tomcat
Create Tomcat User
# useradd -g tomcat -d /opt/tomcat -s /bin/false tomcat
Download and Install Tomcat
Download Tomcat 10.1.x
# wget <link>
Create Directory for Tomcat
# mkdir /opt/tomcat
Unzip Tomcat Archive to /opt/tomcat
# tar xzvf apache-tomcat-10.1.25.tar.gz -C /opt/tomcat --strip-components=1
Change Ownership of Tomcat Directory
# chown -R tomcat: /opt/tomcat
Set Appropriate Permissions for Tomcat Directory
# chmod -R u+rwx /opt/tomcat
Create Tomcat Service File
Create a systemd service file to manage Tomcat as a service.
Create and Edit Tomcat Service File
# vim /etc/systemd/system/tomcat.service
Add the Following Script
[Unit]
Description=Apache Tomcat 10 Web Application Container
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
Environment="JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom"
ExecStart=/opt/t
Enable and Start Tomcat Service
Reload the systemd daemon and start the Tomcat service:
Reload systemd daemon
# systemctl daemon-reload
Start Tomcat service
# systemctl start tomcat
Enable Tomcat to start on boot
# systemctl enable tomcat
Configure Firewall
Ensure the firewall is configured to allow traffic on Tomcat's default port (8080):
Allow traffic on port 8080
# ufw allow 8080/tcp
Reload the firewall to apply changes
# ufw reload