Skip to main content

TOMCAT 8 ON CENTOS 7

First install java package
#yum install java-1.7.0-openjdk-devel
Note:JAVA_HOME directory, which we will need to configure Tomcat later, can be found at /usr/lib/jvm/jre

Create tomcat user and group
#groupadd tomcat
Now create /opt/tomcat directory where we install binaries
#mkdir /opt/tomcat
Create tomcat user with noshell login           
#useradd  -s /bin/nologin -g tomcat -d /opt/tomcat tomcat

Download tomcat binary zip file

Extract package to /opt/tomcat directory
#tar xvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1
#cd /opt/tomcat

Change ownership of files
#chgrp -R tomcat /opt/tomcat
#chmod -R g+r conf
#chmod g+x conf
#chown -R tomcat webapps/ work/ temp/ logs/

Now install systemd unit file (open tomcat.service file and make following entries)
#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/lib/jvm/jre
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


Now start and enable tomcat service
#systemctl daemon-reload
#systemctl start tomcat
#systemctl enable tomcat


From your browser access http://yourip:8080