[LINUX] Tomcat installation and autostart settings

Introduction

Environment used

Java installation

[[email protected] ~]# yum install -y https://corretto.aws/downloads/latest/amazon-corretto-8-x64-linux-jdk.rpm
[[email protected] ~]# java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment Corretto-8.242.08.1 (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM Corretto-8.242.08.1 (build 25.242-b08, mixed mode)

Install tomcat

Install tomcat


[[email protected] ~]# wget https://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.30/bin/apache-tomcat-9.0.30.tar.gz
[[email protected] ~]# mv apache-tomcat-9.0.30.tar.gz /usr/local/
[[email protected] ~]# cd /usr/local/
[[email protected] local]# tar zxvf apache-tomcat-9.0.30.tar.gz 
[[email protected] local]# ls
apache-tomcat-9.0.30         bin  games    lib    libexec  share
apache-tomcat-9.0.30.tar.gz  etc  include  lib64  sbin     src

Start and stop tomcat


[[email protected] local]# sh ./apache-tomcat-9.0.30/bin/startup.sh
Using CATALINA_BASE:   /usr/local/apache-tomcat-9.0.30
Using CATALINA_HOME:   /usr/local/apache-tomcat-9.0.30
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-9.0.30/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/apache-tomcat-9.0.30/bin/bootstrap.jar:/usr/local/apache-tomcat-9.0.30/bin/tomcat-juli.jar
Tomcat started.
[[email protected] local]# sh ./apache-tomcat-9.0.30/bin/shutdown.sh 
Using CATALINA_BASE:   /usr/local/apache-tomcat-9.0.30
Using CATALINA_HOME:   /usr/local/apache-tomcat-9.0.30
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-9.0.30/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/apache-tomcat-9.0.30/bin/bootstrap.jar:/usr/local/apache-tomcat-9.0.30/bin/tomcat-juli.jar

Tomcat autostart settings

Add symbolic link

Add symbolic link


[[email protected] local]# ln -s apache-tomcat-9.0.30 tomcat9
[[email protected] local]# ls -l | grep tomcat9
lrwxrwxrwx 1 root root 20 February 2 13:40 tomcat9 -> apache-tomcat-9.0.30

Creating a tomcat user

Creating a tomcat user


[[email protected] local]# useradd -M tomcat
[[email protected] local]# id tomcat
uid=1001(tomcat) gid=1001(tomcat) groups=1001(tomcat)

Change folder permissions

Change folder permissions


[[email protected] local]# chown tomcat:tomcat -R ./tomcat9/
[[email protected] local]# ls -l | grep tomcat
drwxr-xr-x 9 tomcat tomcat 220 January 26 22:04 apache-tomcat-9.0.30
-rw-r--r--1 root root 11026056 December 8 02:16 apache-tomcat-9.0.30.tar.gz
lrwxrwxrwx 1 root root 20 February 2 13:40 tomcat9 -> apache-tomcat-9.0.30

Creating a unit file

tomcat9.service


[Unit]
Description=Apache Tomcat 9.0.30
ConditionPathExists=/usr/local/tomcat9

[Service]
User=tomcat
Group=tomcat
Type=oneshot

ExecStart=/usr/local/tomcat9/bin/startup.sh
ExecStop=/usr/local/tomcat9/bin/shutdown.sh
Restart=no
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
section option Description
Unit Description A descriptive text that describes this service.
Unit ConditionPathExists Check if the absolute pathname specified here exists before the unit starts.
Service User The user who starts the service.
Service Group The group that starts the service.
Service Type How to confirm that the service has started. Default valuesimpleConsiders the start to be complete when the process starts.oneshotIs used for services that run only once.
Service ExecStart A command to start a service.
Service ExecStop A command to stop the service.
Service Restart Restart conditions when the service is stopped. The default value isno
Service RemainAfterExit The status remains Active even after the process is started.Type=oneshotUseful at the time.
Install WantedBy A setting equivalent to the "runlevel" that enables automatic startup.multi-user.targetIs equivalent to runlevel 3.

Placement of unit files

Placement of unit files


[[email protected] ~]# chmod 755 tomcat9.service 
[[email protected] ~]# cp -a tomcat9.service /etc/systemd/system/
[[email protected] ~]# systemctl daemon-reload
[[email protected] ~]# systemctl list-unit-files --type=service | grep tomcat
tomcat9.service                               disabled

Auto start settings

Auto start settings


[[email protected] ~]# systemctl enable tomcat9
Created symlink from /etc/systemd/system/multi-user.target.wants/tomcat9.service to /etc/systemd/system/tomcat9.service.
[[email protected] ~]# systemctl list-unit-files -t service | grep tomcat9
tomcat9.service                               enabled 

Related article

Recommended Posts

Tomcat installation and autostart settings
goland and Docker settings
jupyter and pandas installation
Integrate Apache and Tomcat
Easy HTTP server and Systemd autostart settings in Go
Python installation and basic grammar
Initial settings from Kubuntu installation
Django installation and operation check
django timezone and language settings
Source installation and installation of Python
Python (Python 3.7.7) installation and basic grammar
Correspondence record of minor troubles in Linux installation and settings, etc.
Installation of SciPy and matplotlib (Python)
Network settings and confirmation in CentOS7
Mavericks and PIL installation is missing
PySpark 1.5.2 + Elasticsearch 2.1.0 Installation procedure and execution
Homebrew and Pycharm installation instructions notes