How to Install and Configure Apache Tomcat 9 in CentOS
Apache Tomcat version 9.0 implements the Servlet 4.0 and JavaServer Pages 2.3 specifications from the Java Community Process, and includes many additional features that make it a useful platform for developing and deploying web applications and web services.
Update the System.
yum update && yum upgrade -y
Installing and Configure Java.
yum install java-1.8.0-openjdk-devel
Verify Installed Java version using below command,
java -version
Output:
[root@vps ~]# java -version
openjdk version "1.8.0_302"
OpenJDK Runtime Environment (build 1.8.0_302-b08)
OpenJDK 64-Bit Server VM (build 25.302-b08, mixed mode)
Create Tomcat system user.
sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat
Installing Apache Tomcat 9
cd /usr/local
wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.21/bin/apache-tomcat-9.0.21.tar.gz
Extract the Package and Rename package name using below command,
tar -xvzf apache-tomcat-9.0.21.tar.gz
mv apache-tomcat-9.0.21 /opt/tomcat
Change Permission and Owenership of the Tomcat directory,
chown -R tomcat: /opt/tomcat
chmod o+x /opt/tomcat/bin/
Configure CATALINA_HOME environment variable using below command,
echo "export CATALINA_HOME="/usr/local/tomcat9"" >> ~/.bashrc
source ~/.bashrc
To run Tomcat as a service, Create tomcat.service
file in the /etc/systemd/system
directory.
Paste the following content:
[Unit]
Description=Tomcat 9 servlet container
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/lib/jvm/jre"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/"
Environment="CATALINA_BASE=/opt/tomcat/apache-tomcat-9.0.21"
Environment="CATALINA_HOME=/opt/tomcat/apache-tomcat-9.0.21"
Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ExecStart=/opt/tomcat/apache-tomcat-9.0.21/bin/startup.sh
ExecStop=/opt/tomcat/apache-tomcat-9.0.21/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
Start and Enable the Tomcat service.
systemctl daemon-reload
systemctl enable tomcat
systemctl start tomcat
Check status of Tomcat service using below command,
systemctl status tomcat
Output:
[root@vps ~]# systemctl status tomcat
● tomcat.service - Tomcat 9 servlet container
Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-09-27 11:05:34 EDT; 22min ago
Process: 12490 ExecStart=/opt/tomcat/apache-tomcat-9.0.21/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 12500 (java)
CGroup: /system.slice/tomcat.service
└─12500 /usr/lib/jvm/jre/bin/java -Djava.util.log...
Now open your browser, go to your IP or Domain with the 8080 port to see Tomcat dashboard,
http://Your_IP:8080
Done.
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME
for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS