在官网上下载tomcat:可以翻译成中文,这里下载8.5,最新的我下的没有关闭文件,但是其他人都有,可能是不稳定把
然后将tomcat包上传到linux中,是哦那个shell和ftp上传
解压tomcat:
root@192 ~]# cd tomcat
[root@192 tomcat]# ls
apache-tomcat-8.5.83.tar.gz
[root@192 tomcat]# tar -zxvf apache-tomcat-8.5.83.tar.gz
[root@192 tomcat]# ls
apache-tomcat-8.5.83 apache-tomcat-8.5.83.tar.gz
将目录apache-tomcat-8.5.83 移动到/usr/java并改名为tomcat8.5
[root@192 tomcat]# mv ./apache-tomcat-8.5.83 /usr/java
[root@192 tomcat]# cd ..
[root@192 java]# ls
apache-tomcat-8.5.83 default jdk1.8.0_191-amd64 latest tomcat
[root@192 java]# mv apache-tomcat-8.5.83 tomcat8.5
[root@192 java]# ls
default jdk1.8.0_191-amd64 latest tomcat tomcat8.5
[root@192 java]# cd tomcat8.5
进入tomcat的bin目录启动tomcat:
# 执行:startup.sh -->启动tomcat
# 执行:shutdown.sh -->关闭tomcat
./startup.sh
./shutdown.sh
[root@192 bin]# ./startup.sh
Using CATALINA_BASE: /usr/java/tomcat8.5
Using CATALINA_HOME: /usr/java/tomcat8.5
Using CATALINA_TMPDIR: /usr/java/tomcat8.5/temp
Using JRE_HOME: /usr/java/jdk1.8.0_221-amd64
Using CLASSPATH: /usr/java/tomcat8.5/bin/bootstrap.jar:/usr/java/tomcat8.5/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
确保Linux的防火墙端口是开启的,如果是阿里云,需要保证阿里云的安全组策略是开放的!
# 查看firewall服务状态
systemctl status firewalld
# 开启、重启、关闭、firewalld.service服务
# 开启
service firewalld start
# 重启
service firewalld restart
# 关闭
service firewalld stop
# 查看防火墙规则
firewall-cmd --list-all # 查看全部信息
firewall-cmd --list-ports # 只看端口信息
# 开启端口
开端口命令:firewall-cmd --zone=public --add-port=8080/tcp --permanent
重启防火墙:systemctl restart firewalld.service
命令含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
然后我8080端口是开启的,但是远程就是访问不了
查看tomcat8.5目录下的logs日志
[root@192 logs]# ls
catalina.out
[root@192 logs]# cat catalina.out
/root/tomcat/apache-tomcat-8.5.83/bin/catalina.sh:行504: /usr/java/jdk1.8.0_221-amd64/bin/java: 没有那个文件或目录
查看/usr/java/下的jdk名称:
[root@192 java]# ls
apache-tomcat-8.5.83 default jdk1.8.0_191-amd64 latest tomcat
查看/etc/profile文件中的java_home配置
[root@192 logs]# tac /etc/profile
export PATH CLASSPATH JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
CLASSPATH=%JAVA_HOME%/lib:%JAVA_HOME%/jre/lib
JAVA_HOME=/usr/java/jdk1.8.0_191-amd64
我的做法:将java目录下的jdk目录名和/etc/profile文件中的java_home配置都改为tomcat启动日志中报错的未找到的目录:dk1.8.0_221-amd64,这里就不展示vim了,就改个名,其他不动
[root@192 java]# mv jdk1.8.0_191-amd64 jdk1.8.0_221-amd64
[root@192 java]# vim /etc/profile
然后重新启动tomcat(在tomcat的bin目录下执行./startup.sh,这里未tomcat8.5),查看log下的日志:可以看到会出现多个文件,我们打开之前的看的文件,看到如下:
[root@192 logs]# ls
catalina.2022-10-30.log catalina.out host-manager.2022-10-30.log localhost.2022-10-30.log localhost_access_log.2022-10-30.txt manager.2022-10-30.log
[root@192 logs]# ls
catalina.2022-10-30.log catalina.out host-manager.2022-10-30.log localhost.2022-10-30.log localhost_access_log.2022-10-30.txt manager.2022-10-30.log
[root@192 logs]# cat catalina.2022-10-30.log
30-Oct-2022 15:42:14.280 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server.服务器版本: Apache Tomcat/8.5.83
30-Oct-2022 15:42:14.297 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器构建: Oct 3 2022 21:11:09 UTC
30-Oct-2022 15:42:14.298 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器版本号: 8.5.83.0
30-Oct-2022 15:42:14.298 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 操作系统名称: Linux
30-Oct-2022 15:42:14.298 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS.版本: 3.10.0-957.el7.x86_64
30-Oct-2022 15:42:14.298 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 架构: amd64
30-Oct-2022 15:42:14.298 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java 环境变量: /usr/java/jdk1.8.0_221-amd64/jre
30-Oct-2022 15:42:14.298 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java虚拟机版本: 1.8.0_191-b12
30-Oct-2022 15:42:14.298 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM.供应商: Oracle Corporation
30-Oct-2022 15:42:14.298 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/java/tomcat8.5
30-Oct-2022 15:42:14.298 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/java/tomcat8.5
30-Oct-2022 15:42:14.298 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.util.logging.config.file=/usr/java/tomcat8.5/conf/logging.properties
30-Oct-2022 15:42:14.298 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
30-Oct-2022 15:42:14.298 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djdk.tls.ephemeralDHKeySize=2048
30-Oct-2022 15:42:14.298 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
30-Oct-2022 15:42:14.298 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
30-Oct-2022 15:42:14.299 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dignore.endorsed.dirs=
30-Oct-2022 15:42:14.299 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dcatalina.base=/usr/java/tomcat8.5
30-Oct-2022 15:42:14.299 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dcatalina.home=/usr/java/tomcat8.5
30-Oct-2022 15:42:14.299 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.io.tmpdir=/usr/java/tomcat8.5/temp
30-Oct-2022 15:42:14.299 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent 在java.library.path:[/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]上找不到基于APR的Apache Tomcat本机库,该库允许在生产环境中获得最佳性能
30-Oct-2022 15:42:14.496 信息 [main] org.apache.coyote.AbstractProtocol.init 初始化协议处理器 ["http-nio-8080"]
30-Oct-2022 15:42:14.555 信息 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 965 ms
30-Oct-2022 15:42:14.608 信息 [main] org.apache.catalina.core.StandardService.startInternal 正在启动服务[Catalina]
30-Oct-2022 15:42:14.609 信息 [main] org.apache.catalina.core.StandardEngine.startInternal 正在启动 Servlet 引擎:[Apache Tomcat/8.5.83]
30-Oct-2022 15:42:14.647 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/java/tomcat8.5/webapps/ROOT]
30-Oct-2022 15:42:15.048 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[/usr/java/tomcat8.5/webapps/ROOT]的部署已在[402]毫秒内完成
30-Oct-2022 15:42:15.048 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/java/tomcat8.5/webapps/docs]
30-Oct-2022 15:42:15.080 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[/usr/java/tomcat8.5/webapps/docs]的部署已在[32]毫秒内完成
30-Oct-2022 15:42:15.080 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/java/tomcat8.5/webapps/examples]
30-Oct-2022 15:42:15.452 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[/usr/java/tomcat8.5/webapps/examples]的部署已在[372]毫秒内完成
30-Oct-2022 15:42:15.452 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/java/tomcat8.5/webapps/host-manager]
30-Oct-2022 15:42:15.500 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[/usr/java/tomcat8.5/webapps/host-manager]的部署已在[48]毫秒内完成
30-Oct-2022 15:42:15.501 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/java/tomcat8.5/webapps/manager]
30-Oct-2022 15:42:15.526 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[/usr/java/tomcat8.5/webapps/manager]的部署已在[25]毫秒内完成
30-Oct-2022 15:42:15.540 信息 [main] org.apache.coyote.AbstractProtocol.start 开始协议处理句柄["http-nio-8080"]
30-Oct-2022 15:42:15.577 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 1021 ms
然后再次远程连接tomcat
连接成功看防火墙允许的端口
[root@192 tomcat8.5]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
Warning: ALREADY_ENABLED: 8080:tcp
success
[root@192 tomcat8.5]#
java_home对应就行,jdk是没影响的
[root@192 java]# java -jar mybatis_demo-0.0.1-SNAPSHOT.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.2)
2022-10-30 16:18:16.445 INFO 14518 --- [ main] c.e.mybatis_demo.MybatisDemoApplication : Starting MybatisDemoApplication v0.0.1-SNAPSHOT using Java 1.8.0_191 on 192.168.133.130 with PID 14518 (/root/root/java/mybatis_demo-0.0.1-SNAPSHOT.jar started by root in /root/root/java)
2022-10-30 16:18:16.462 INFO 14518 --- [ main] c.e.mybatis_demo.MybatisDemoApplication : No active profile set, falling back to 1 default profile: "default"
2022-10-30 16:18:18.930 INFO 14518 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8093 (http)
2022-10-30 16:18:18.969 INFO 14518 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-10-30 16:18:18.970 INFO 14518 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-10-30 16:18:19.229 INFO 14518 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-10-30 16:18:19.229 INFO 14518 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2663 ms
2022-10-30 16:18:21.299 INFO 14518 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8093 (http) with context path ''
2022-10-30 16:18:21.330 INFO 14518 --- [ main] c.e.mybatis_demo.MybatisDemoApplication : Started MybatisDemoApplication in 5.904 seconds (JVM running for 6.705)