Friday, April 17, 2020

Install Tomcat On Centos 7

Description: Here I have explained how to install Tomcat on Centos 7

Procedure: 
  • Install JDK: Tomcat 9 require java 8 or later. You can install java using below command.
# yum install java-1.8.0-openjdk-devel

  • Verify Java Version: 
# java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
  • Create User For Tomcat:  For security purpose create user with group and home directory for tomcat.
# useradd -m -U -d /opt/tomcat -s /bin/false tomcat
  • Download Tomcat : We will download latest version of  Tomcat from Tomcat Download Site Navigate to /tmp directory and download using wget command.
# cd /tmp
# wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.34/bin/apache-tomcat-9.0.34.tar.gz
  • Extract tar file 
tar -zxvf apache-tomcat-9.0.34.tar.gz
  • Move folder to opt drive
# mv apache-tomcat-9.0.34.tar.gz /opt/tomcat/
  • Change User ownership 
chown -R tomcat: /opt/tomcat
  • Executable File:  Make the scripts inside the bin directory executable by issuing the following chmod command:
# chmod +x /opt/tomcat/bin/*.sh
  • Create Tomcat Service : Create service to start or stop tomcat and paste below content.
# vi /etc/systemd/system/tomcat.service

[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/urandom"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

[Install]
WantedBy=multi-user.target
  • Save file and notify systemd that we created a new unit file by typing:
# systemctl daemon-reload
  • Start and Enable Service
# systemctl enable tomcat
# systemctl start tomcat
  • Setup firewall and enable tomcat port
# firewall-cmd --zone=public --permanent --add-port=8080/tcp
# firewall-cmd --reload
  • Browse URL http://IP_ADDRESS:8080

No comments:

Post a Comment