1.官网下载对应版本:https://tomcat.apache.org/,下载 “tar.gz ”压缩包。
2.使用fianlshell工具上传至服务器并解压:
[root@iZbp1ganqt1lx0rpzog8z2Z tools]# tar -zxvf apache-tomcat-8.5.87.tar.gz -C /opt/apps
3.修改apache-tomcat-8.5.87.tar.gz名称为:tomcat-8.5方便后续操作
[root@iZbp1ganqt1lx0rpzog8z2Z tools]# mv apache-tomcat-8.5.87/ tomcat-8.5
4.切换至tomcat的bin目录下:
[root@iZbp1ganqt1lx0rpzog8z2Z tools]# cd /opt/apps/tomcat-8.5/bin
5.启动tomcat,出现一下信息表示启动成功
[root@iZbp1ganqt1lx0rpzog8z2Z bin]# ./startup.sh
Using CATALINA_BASE: /opt/apps/tomcat-8.5
Using CATALINA_HOME: /opt/apps/tomcat-8.5
Using CATALINA_TMPDIR: /opt/apps/tomcat-8.5/temp
Using JRE_HOME: /usr/local/jdk1.8.0_361/jre
Using CLASSPATH: /opt/apps/tomcat-8.5/bin/bootstrap.jar:/opt/apps/tomcat-8.5/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
6.查看防火墙状态:
[root@iZbp1ganqt1lx0rpzog8z2Z ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
7.防火墙状态为: Active: inactive (dead)表示未启用,执行命令开启防火墙
[root@iZbp1ganqt1lx0rpzog8z2Z ~]# service firewalld start
Redirecting to /bin/systemctl start firewalld.service
在执行第六步命令,出现一下信息表示防火墙以启用:
[root@iZbp1ganqt1lx0rpzog8z2Z ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: active (running) since 六 2023-03-25 15:13:39 CST; 4s ago
Docs: man:firewalld(1)
Main PID: 3005 (firewalld)
Tasks: 2
Memory: 26.1M
CGroup: /system.slice/firewalld.service
└─3005 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
3月 25 15:13:38 iZbp1ganqt1lx0rpzog8z2Z systemd[1]: Starting firewalld - dynamic firewall daemon...
3月 25 15:13:39 iZbp1ganqt1lx0rpzog8z2Z systemd[1]: Started firewalld - dynamic firewall daemon.
3月 25 15:13:39 iZbp1ganqt1lx0rpzog8z2Z firewalld[3005]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be re...g it now.
Hint: Some lines were ellipsized, use -l to show in full.
8.查看开启端口号:一下信息表示没有端口开启
[root@iZbp1ganqt1lx0rpzog8z2Z ~]# firewall-cmd --list-all
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
9.开启端口:
[root@iZbp1ganqt1lx0rpzog8z2Z ~]# firewall-cmd --zone=public --permanent --add-port=8080/tcp
success
10.开启成功后进行刷新操作
[root@iZbp1ganqt1lx0rpzog8z2Z ~]# firewall-cmd --reload
success
再次执行第八步进行查看,出现一下信息表示操作成功
[root@iZbp1ganqt1lx0rpzog8z2Z ~]# firewall-cmd --list-all
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: dhcpv6-client ssh
ports: 8080/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
11.访问tomcat,输入http://localhost:8080/,输入对应ip地址
①如果访问不了,进一步查看/opt/apps/tomcat-8.5/logs/catalina.out 该文件下的日志信息,出现以下信息:
/opt/apps/tomcat-8.5/bin/catalina.sh:行504: /usr/local/jdk1.8.0_361/jre/bin/java: 没有那个文件或目录
②找到/opt/apps/tomcat-8.5/bin/catalina.sh该文件进行修改,添加一下信息即可:
export JAVA_HOME=/opt/apps/jdk1.8.0_361
export JRE_HOME=/opt/apps/jdk1.8.0_361/jre