top of page
Recent Posts
  • Zakir

How to install tomcat web server in a portable way?

Updated: Oct 3, 2021

Apache Tomcat is an open-source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and WebSocket technologies. Tomcat provides a "pure Java" HTTP web server environment in which Java code can run. In this post i will discuss how to install tomcat in a portable manner.


Step-01: Create Tomcat user

# useradd -s /sbin/false tomcat

# echo "password" | passwd tomcat --stdin


Step-02: Create Environment for Tomcat user

# mkdir /home/tomcat/APACHE

# mkdir /home/tomcat/JAVA


Step-03: Download Tomcat and JAVA from below URL

cd /home/tomcat/APACHE


Download your desire version from below link:

Tomcat: https://tomcat.apache.org/

JAVA: https://www.oracle.com/java/technologies/javase-jre8-downloads.html


# tar -xvf apache-tomcat-8.5.57.tar.gzip

# cd /home/tomcat/JAVA

# tar -xvf jre-8u102-linux-x64.tar.gzip


Step-04: Install Tomcat and JAVA

# ln -s /home/tomcat/APACHE/apache-tomcat-8.5.57 /home/tomcat/APACHE/apache-tomcat

# ln -s /home/tomcat/JAVA/jre1.8.0_102 /home/tomcat/JAVA/jre

# cd /home/tomcat

# chown -R tomcat:tomcat *


# vim /home/tomcat/.bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH

# Environment for tomcat user
export JRE_HOME=/home/tomcat/JAVA/jre
export CLASSPATH=$CLASSPATH:$JRE_HOME/lib
export PATH=$JRE_HOME/bin:$PATH:$HOME/bin

Load the bash profile

# source /home/tomcat/.bash_profile


Step-05: Create Startup Systemd Script for RHEL / CentOS 7~8


# vim /etc/systemd/system/tomcat.service

[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/home/tomcat/JAVA/jre
Environment=JRE_HOME=/home/tomcat/JAVA/jre
Environment=CATALINA_PID=/home/tomcat/APACHE/apache-tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/home/tomcat/APACHE/apache-tomcat
Environment=CATALINA_BASE=/home/tomcat/APACHE/apache-tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx5120M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/home/tomcat/APACHE/apache-tomcat/bin/startup.sh
ExecStop=/home/tomcat/APACHE/apache-tomcat/bin/shutdown.sh

User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target

# systemctl daemon-reload

# systemctl start tomcat

# systemctl enable tomcat


Step-05: Create Startup Systemd Script for RHEL / CentOS 6

init.tomcat
.txt
Download TXT • 2KB

Download above script into /etc/init.d/ directory then follow steps:

# mv /etc/init.d/init.tomcat.txt /etc/init.d/init.tomcat

# chmod +x /etc/init.d/init.tomcat

# /etc/init.d/init.tomcat start

# chkconfig --level 3,5 init.tomcat on


That's it.

Hope this will help.




81 views1 comment

Recent Posts

See All

Device configuration backup is vital task for IT people especially those who are working as a administrator. To make this task easier i have create Ansible playbook for CISCO switches. Below i will sh