yum command, which makes package management easy.[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)
yum command, but since the version of Tomcat is 7.0, which is quite old, I downloaded it from the official website of Tomcat this time.startup.sh and shutdown.sh to verify that Tomcat can be started / stopped normally.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
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
tomcat to use when starting Tomcat automatically.-M option is added to the ʻuseradd` command.Creating a tomcat user
[root@akagi local]# useradd -M tomcat
[root@akagi local]# id tomcat
uid=1001(tomcat) gid=1001(tomcat) groups=1001(tomcat)
tomcat user created earlier can start Tomcat.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
unit file for systemd with the name tomcat9.service.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. | 
tomcat9.service under/ etc / systemd / system /and set Tomcat to start automatically.systemctl list-unit-files ... is bad instead of disabled, please review the following points./ etc / systemd / system /.[ is {, it will be bad.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
systemctl enable ..., and finally check the automatic start setting to complete.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 
Recommended Posts