- 去官网下载 数据包
ps:
wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.78/bin/apache-tomcat-9.0.78.tar.gz
- 检查Java环境
[tomcat@localhost bin]$ java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
[tomcat@localhost bin]$ echo $JAVA_HOME
/home/tomcat/jdk1.8.0_121
[tomcat@localhost bin]$ echo $JRE_HOME
/home/tomcat/jdk1.8.0_121/jre
PS: Java 1.8(也称为Java 8)支持的Tomcat版本是Tomcat 8和Tomcat 9。Tomcat 8和Tomcat 9都是为Java 1.8版本设计的,并且不支持Java 1.7及更低版本。
以下是Tomcat 8.x 和 Tomcat 9.x 版本的一些重要发布:
Tomcat 8.0.0 - Tomcat 8.5.x:支持Java 1.8(Java 8)。
Tomcat 9.0.0 及以上版本:支持Java 1.8(Java 8)。
3. 创建用户和组
groupadd tomcat
useradd -g tomcat tomcat
- 赋权
[tomcat@localhost ~] chmod +x apache-tomcat-9.0.78 -R
[tomcat@localhost ~]$ ll
total 0
drwxrwxr-x 9 tomcat tomcat 220 Jul 27 23:15 apache-tomcat-9.0.78
drwxr-xr-x 8 root root 255 Jul 27 22:49 jdk1.8.0_121
- 配置环境变量
vim ~/.bashrc
export CATALINA_HOME=/home/tomcat/apache-tomcat-9.0.78
export PATH=$PATH:$CATALINA_HOME/bin
[tomcat@localhost bin]$ source ~/.bashrc
- 启动
[tomcat@localhost bin]$ startup.sh run
Using CATALINA_BASE: /home/tomcat/apache-tomcat-9.0.78
Using CATALINA_HOME: /home/tomcat/apache-tomcat-9.0.78
Using CATALINA_TMPDIR: /home/tomcat/apache-tomcat-9.0.78/temp
Using JRE_HOME: /home/tomcat/jdk1.8.0_121/jre
Using CLASSPATH: /home/tomcat/apache-tomcat-9.0.78/bin/bootstrap.jar:/home/tomcat/apache-tomcat-9.0.78/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
- 查看日志
[tomcat@localhost bin]$ cat ../logs/catalina.out
27-Jul-2023 23:16:33.344 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/9.0.78
27-Jul-2023 23:16:33.346 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Jul 4 2023 13:15:43 UTC
.....
27-Jul-2023 23:42:13.263 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/home/tomcat/apache-tomcat-9.0.78/webapps/host-manager]
27-Jul-2023 23:42:13.279 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/home/tomcat/apache-tomcat-9.0.78/webapps/host-manager] has finished in [16] ms
27-Jul-2023 23:42:13.279 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/home/tomcat/apache-tomcat-9.0.78/webapps/manager]
27-Jul-2023 23:42:13.293 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/home/tomcat/apache-tomcat-9.0.78/webapps/manager] has finished in [13] ms
27-Jul-2023 23:42:13.295 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
27-Jul-2023 23:42:13.303 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [436] milliseconds
- 查看效果
- 关于一些报错问题
[tomcat@localhost bin]$ ./startup.sh run
The JRE_HOME environment variable is not defined correctly
JRE_HOME=/usr/lib/jdk1.8.0_121/jre
This environment variable is needed to run this program
[tomcat@localhost bin]$ catalina.sh run
The JRE_HOME environment variable is not defined correctly
JRE_HOME=/usr/lib/jdk1.8.0_121/jre
This environment variable is needed to run this program
[root@localhost logs]# cat catalina.out
Error: Could not find or load main class org.apache.catalina.startup.Bootstrap
Error: Could not find or load main class org.apache.catalina.startup.Bootstrap
出现上述的情况很大可能就是你文件下错了,或者没有配置Java jre环境,可以试着echo $JRE_HOME