Centos8安装Tomcat8.5.55

Centos8安装Tomcat8.5.55

  • 下载
  • 创建目录进入
    • 下载tomcat
  • 解压
  • 启动
    • 启动
    • 停止
  • 配置systemctl 管理
    • 创建 tomcat.service
    • 启动错误解决
    • 使用

下载

tomcat官网
直达下载 apache-tomcat-8.5.55.tar.gz

创建目录进入

[root@localhost work]# mkdir /home/work/tomcat
[root@localhost work]# cd /home/work/tomcat/

下载tomcat

[root@localhost tomcat]# wget https://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.55/bin/apache-tomcat-8.5.55.tar.gz
--2020-05-26 22:02:38--  https://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.55/bin/apache-tomcat-8.5.55.tar.gz
Resolving mirror.bit.edu.cn (mirror.bit.edu.cn)... 114.247.56.117, 2001:da8:204:1205::22
Connecting to mirror.bit.edu.cn (mirror.bit.edu.cn)|114.247.56.117|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10371538 (9.9M) [application/octet-stream]
Saving to: ‘apache-tomcat-8.5.55.tar.gz’

apache-tomcat-8.5.55.tar.g 100%[=======================================>]   9.89M  4.23MB/s    in 2.3s    

2020-05-26 22:02:41 (4.23 MB/s) - ‘apache-tomcat-8.5.55.tar.gz’ saved [10371538/10371538]

解压

[root@localhost tomcat]# tar -zxvf apache-tomcat-8.5.55.tar.gz 

启动

  • 启动 ./startup.sh
  • 停止 ./shutdown.sh

启动

[root@localhost bin]# pwd
/home/work/tomcat/apache-tomcat-8.5.55/bin
[root@localhost bin]# ll
total 864
-rw-r----- 1 root root  35374 May  6 06:12 bootstrap.jar
-rw-r----- 1 root root  16608 May  6 06:12 catalina.bat
-rwxr-x--- 1 root root  24397 May  6 06:12 catalina.sh
-rw-r----- 1 root root   1664 May  6 06:14 catalina-tasks.xml
-rw-r----- 1 root root   2123 May  6 06:12 ciphers.bat
-rwxr-x--- 1 root root   1997 May  6 06:12 ciphers.sh
-rw-r----- 1 root root  25197 May  6 06:12 commons-daemon.jar
-rw-r----- 1 root root 206895 May  6 06:12 commons-daemon-native.tar.gz
-rw-r----- 1 root root   2040 May  6 06:12 configtest.bat
-rwxr-x--- 1 root root   1922 May  6 06:12 configtest.sh
-rwxr-x--- 1 root root   9127 May  6 06:12 daemon.sh
-rw-r----- 1 root root   2091 May  6 06:12 digest.bat
-rwxr-x--- 1 root root   1965 May  6 06:12 digest.sh
-rw-r----- 1 root root   3460 May  6 06:12 setclasspath.bat
-rwxr-x--- 1 root root   3708 May  6 06:12 setclasspath.sh
-rw-r----- 1 root root   2020 May  6 06:12 shutdown.bat
-rwxr-x--- 1 root root   1902 May  6 06:12 shutdown.sh
-rw-r----- 1 root root   2022 May  6 06:12 startup.bat
-rwxr-x--- 1 root root   1904 May  6 06:12 startup.sh
-rw-r----- 1 root root  51231 May  6 06:12 tomcat-juli.jar
-rw-r----- 1 root root 419572 May  6 06:12 tomcat-native.tar.gz
-rw-r----- 1 root root   4574 May  6 06:12 tool-wrapper.bat
-rwxr-x--- 1 root root   5540 May  6 06:12 tool-wrapper.sh
-rw-r----- 1 root root   2026 May  6 06:12 version.bat
-rwxr-x--- 1 root root   1908 May  6 06:12 version.sh
[root@localhost bin]# ./startup.sh 
Using CATALINA_BASE:   /home/work/tomcat/apache-tomcat-8.5.55
Using CATALINA_HOME:   /home/work/tomcat/apache-tomcat-8.5.55
Using CATALINA_TMPDIR: /home/work/tomcat/apache-tomcat-8.5.55/temp
Using JRE_HOME:        /home/work/java/jdk1.8.0_191/jre
Using CLASSPATH:       /home/work/tomcat/apache-tomcat-8.5.55/bin/bootstrap.jar:/home/work/tomcat/apache-tomcat-8.5.55/bin/tomcat-juli.jar
Tomcat started.
[root@localhost bin]# 

停止

[root@localhost bin]# ./shutdown.sh 
Using CATALINA_BASE:   /home/work/tomcat/apache-tomcat-8.5.55
Using CATALINA_HOME:   /home/work/tomcat/apache-tomcat-8.5.55
Using CATALINA_TMPDIR: /home/work/tomcat/apache-tomcat-8.5.55/temp
Using JRE_HOME:        /home/work/java/jdk1.8.0_191/jre
Using CLASSPATH:       /home/work/tomcat/apache-tomcat-8.5.55/bin/bootstrap.jar:/home/work/tomcat/apache-tomcat-8.5.55/bin/tomcat-juli.jar
[root@localhost bin]# 

配置systemctl 管理

创建 tomcat.service

[root@localhost bin]# vi /etc/systemd/system/tomcat.service
[root@localhost bin]# cat /etc/systemd/system/tomcat.service
[Unit]
Description=Tomcat8540
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=oneshot
ExecStart=/home/work/tomcat/apache-tomcat-8.5.55/bin/startup.sh
ExecStop=/home/work/tomcat/apache-tomcat-8.5.55/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

[root@localhost bin]# 

启动错误解决

直接使用systemctl启动Tomcat会因找不到java的路径报错

[root@localhost bin]# systemctl start tomcat
Job for tomcat.service failed because the control process exited with error code.
See "systemctl status tomcat.service" and "journalctl -xe" for details.

设置tomcat的java的环境变量
在原文 Make sure prerequisite environment variables are set 前面添加

export JAVA_HOME=/home/work/java/jdk1.8.0_191
export JRE_HOME=/home/work/java/jdk1.8.0_191/jre
[root@localhost bin]# vi setclasspath.sh 

export JAVA_HOME=/home/work/java/jdk1.8.0_191
export JRE_HOME=/home/work/java/jdk1.8.0_191/jre

# Make sure prerequisite environment variables are set
if [ -z "$JAVA_HOME" ] && [ -z "$JRE_HOME" ]; then

使用

  • 启动 systemctl start tomcat
  • 停止 systemctl stop tomcat
  • 状态 systemctl status tomcat
  • 打开开机自启 systemctl enable tomcat
  • 关闭开机自启 systemctl disable tomcat

你可能感兴趣的:(坚持学习,未来可期,#,CentOS8,tomcat)