Sunday, 1 August 2021

Apache Tomcat 9 Installation on Centos 8

Pre-Requirement:

Update repo details
sudo sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*

sudo sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

Please Follow below instructions to install and configure Tomcat on CentOS 8 machine

1)  Install epel-release.

sudo yum install epel-release -y
2) Install open-jdk
sudo yum install java-11-openjdk -y
3)  Download Apache Tomcat 
  cd /opt/        sudo wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.50/bin/apache-tomcat-9.0.50.tar.gz
  sudo tar -zxvf apache-tomcat-9.0.50.tar.gz   sudo mv apache-tomcat-9.0.50 tomcat
  sudo chmod -R 777 tomcat
  sudo chown -R vagrant:vagrant tomcat
4) Configure Apache Tomcat 9 as system service. 
    Create tomcat service file and add below content.

    sudo vi /etc/systemd/system/tomcat.service


[Unit]
Description=Tomcat 9
After=network.target

[Service]
Type=forking

User=vagrant
Group=vagrant

Environment="JAVA_HOME=/usr/lib/jvm/jre"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

[Install]
WantedBy=multi-user.target
  
5) Start tomcat service
sudo systemctl start tomcat
6) Enable tomcat service
sudo systemctl enable tomcat