We Value Your Time – OpenSource Community
We Value Your Time – OpenSource Community

Tomcat Installation on Linux RHEL and Centos 7

Apache Tomcat Installation on Linux (RHEL 7 and Centos 7) in Highly Secure Mode

Apache Tomcat often referred to as Tomcat Server, is an open-source Java Servlet Container developed by the Apache Software Foundation (ASF). Tomcat Installation on Linux is very easy and quick .

  • Set hostname of Linux machine as per your requirement like we are setting below:
[root@node27 ~]# hostnamectl set-hostname jenkins.dockerhunt.com
  • Set IP mapping of your machine hostname in /etc/hosts:
root@node27 ~]# echo 192.168.43.27 jenkins.dockerhunt.com jenkins >> /etc/hosts
  • Setting JAVA:

1: Download latest stable JDK and extract

[root@node27 ~]# tar -xvf jre-8u121-linux-x64.tar.gz

2: Create directory for java

[root@node27 ~]# mkdir /usr/java

3: Move Java folder in to /usr/java

[root@node27 ~]# mv jre1.8.0_121 /usr/java/

4: Export Java home and bin like below,

[root@node27 ~]# export JAVA_HOME=/usr/java/jre1.8.0_121
[root@node27 ~]# export PATH=$PATH:$JAVA_HOME/bin/

5: Check Java version,

[root@node27 bin]# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
  • Setting up tomcat:

1: Download latest stable tomcat zip file and unzip it

[root@node27 ~]# unzip apache-tomcat-7.0.76.zip

2: Create tomcat user and group

[root@node27 ~]# groupadd tomcat
[root@node27 ~]# sudo useradd -M -s /bin/nologin -g tomcat -d /opt/tomcat tomcat

3: Create tomcat home directory

[root@node27 ~]# mkdir /opt/tomcat

4: Move tomcat file into tomcat home

[root@node27 ~]# mv apache-tomcat-7.0.76/* /opt/tomcat/

5: Setup required file and directory permission on tomcat file

[root@node27 ~]# chgrp -R tomcat /opt/tomcat
[root@node27 ~]# chmod -R g+r /opt/tomcat/conf
[root@node27 ~]# chmod g+x /opt/tomcat/
[root@node27 ~]# chmod g+x /opt/tomcat/bin/*
[root@node27 ~]# chmod -R g+w /opt/tomcat/logs
[root@node27 ~]# chmod -R g+w /opt/tomcat/webapps/
[root@node27 ~]# chmod -R g+w /opt/tomcat/work/
[root@node27 ~]# chmod -R g+w /opt/tomcat/temp/

6: Create systemd service file for tomcat

vi /etc/systemd/system/tomcat.service

# Systemd unit file for tomcat
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/java/jre1.8.0_121
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/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

7: Start tomcat service

[root@node27 ~]# systemctl start tomcat

8: Check tomcat service status

[root@node27 ~]# systemctl status tomcat
● tomcat.service - Apache Tomcat Web Application Container
Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2017-03-24 00:56:17 IST; 35s ago
Process: 12259 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 12266 (java)
CGroup: /system.slice/tomcat.service
└─12266 /usr/java/jre1.8.0_121/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties -Djava.util.l...




9: Enable tomcat service on system startup

[root@node27 tomcat]# systemctl enable tomcat

Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “Tomcat Installation on Linux RHEL and Centos 7”