[LINUX] Tomcat installation and autostart settings

Introduction

Environment used

Java installation

[root@akagi ~]# yum install -y https://corretto.aws/downloads/latest/amazon-corretto-8-x64-linux-jdk.rpm
[root@akagi ~]# 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


[root@akagi ~]# wget https://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.30/bin/apache-tomcat-9.0.30.tar.gz
[root@akagi ~]# mv apache-tomcat-9.0.30.tar.gz /usr/local/
[root@akagi ~]# cd /usr/local/
[root@akagi local]# tar zxvf apache-tomcat-9.0.30.tar.gz 
[root@akagi 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


[root@akagi 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.
[root@akagi 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


[root@akagi local]# ln -s apache-tomcat-9.0.30 tomcat9
[root@akagi 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


[root@akagi local]# useradd -M tomcat
[root@akagi local]# id tomcat
uid=1001(tomcat) gid=1001(tomcat) groups=1001(tomcat)

Change folder permissions

Change folder permissions


[root@akagi local]# chown tomcat:tomcat -R ./tomcat9/
[root@akagi 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


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

Auto start settings

Auto start settings


[root@akagi ~]# systemctl enable tomcat9
Created symlink from /etc/systemd/system/multi-user.target.wants/tomcat9.service to /etc/systemd/system/tomcat9.service.
[root@akagi ~]# 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