Centos8(7)安装tomcat9和常见用法
   1 分钟阅读    邵晨峰

Centos8(7)安装tomcat9和常见用法

1.安装jdk

tomcat9可以工作在jdk8及之后的版本

所以可以安装jdk8或是jdk11

dnf install java-11-openjdk # centos8
yum install java-11-openjdk # centos7

2.下载最新的tomcat二进制包

打开网站 https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/

在这里找到最新版本,进入后进入bin目录

里面有名为 apache-tomcat-XXXX.tar.gz 的文件,右键复制地址

下载并解压

wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.31/bin/apache-tomcat-9.0.31.tar.gz
tar xvf apache-tomcat-9.0.31.tar.gz

移动到安装目录

mv apache-tomcat-9.0.31 /opt/tomcat9

3.常见命令和目录

命令或目录 作用
/opt/tomcat9/bin/startup.sh 启动tomcat
/opt/tomcat9/bin/shutdown.sh 关闭tomcat
/opt/tomcat9/conf/ 配置
/opt/tomcat9/logs/ 日志
/opt/tomcat9/webapps/ 默认应用目录

4.如何选择tomcat版本

下面表格来自tomcat官网

Servlet 规范 JSP 规范 EL 规范 WebSocket 规范 JASPIC 规范 Apache Tomcat 版本 最新版本(2020.2.19) 支持的 Java 版本
4.0 2.3 3.0 1.1 1.1 9.0.x 9.0.31 8 and later
3.1 2.3 3.0 1.1 1.1 8.5.x 8.5.51 7 and later
3.1 2.3 3.0 1.1 N/A 8.0.x (superseded) 8.0.53 (superseded) 7 and later
3.0 2.2 2.2 1.1 N/A 7.0.x 7.0.100 6 and later (7 and later for WebSocket)
2.5 2.1 2.1 N/A N/A 6.0.x (archived) 6.0.53 (archived) 5 and later
2.4 2.0 N/A N/A N/A 5.5.x (archived) 5.5.36 (archived) 1.4 and later
2.3 1.2 N/A N/A N/A 4.1.x (archived) 4.1.40 (archived) 1.3 and later
2.2 1.1 N/A N/A N/A 3.3.x (archived) 3.3.2 (archived) 1.1 and later