15158846557 在线咨询 在线咨询
15158846557 在线咨询
所在位置: 首页 > 营销资讯 > 网站运营 > 关于 Tomcat 技术,收藏这一篇足够了!

关于 Tomcat 技术,收藏这一篇足够了!

时间:2023-07-15 05:48:02 | 来源:网站运营

时间:2023-07-15 05:48:02 来源:网站运营

关于 Tomcat 技术,收藏这一篇足够了!:

一、JRE-JDK-JVM

初识JAVA环境,3大必会内容:JRE、JDK、JVM,下面我们来说说他们的区别与特点吧。

1. 为何用JVM?

开发人员正常书写的程序代码,只能在某个平台使用,Linux和Windows软件包是互不通用的,如果把window QQ.exe上传到Linux下面则无法安装与使用。

但是有了JVM,Java环境只要书写一份Java代码,把代码放在Java虚拟机中运行,只要Java虚拟机可以运行,Java代码就可以正常运行。

2. 名词解释

二、Tomcat快速实战指南

1. 环境准备

2. JDK、Tomcat版本选型

jdk版本一般根据开发使用的版本为准,这里我们选择的是1.8.0。

jdk(Oracle官方)

openJDK Linux

tomcat 9.0 8.5 8.0 7.x

3. 极速部署

#oldboy-web-java-01##jdk #各种版本:https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/####01 部署 jdk[root@oldboy-web-java-01 ~]# tar xf /app/tools/jdk-8u241-linux-x64.tar.gz -C /app/[root@oldboy-web-java-01 ~]# ln -s /app/jdk1.8.0_241/ /app/jdk[root@oldboy-web-java-01 ~]# ll /apptotal 0lrwxrwxrwx 1 root root 18 Feb 7 10:26 jdk -> /app/jdk1.8.0_241/drwxr-xr-x 7 10143 10143 245 Dec 11 18:39 jdk1.8.0_241drwxr-xr-x 2 root root 75 Feb 7 10:13 tools####02 java jdk 环境变量 cat >>/etc/profile<<'EOF'export JAVA_HOME=/app/jdkexport PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATHexport CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jarexport TOMCAT_HOME=/app/tomcatEOF#说明部分##export JAVA_HOME=/app/jdk #jdk目录##export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH #配置命令路径##export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar##export TOMCAT_HOME=/app/tomcat #tomcat 目录 [root@oldboy-web-java-01 ~]# . /etc/profile #或者source /etc/profile####03.检查 jdk是否部署完成 [root@oldboy-web-java-01 ~]# java -version java version "1.8.0_241"Java(TM) SE Runtime Environment (build 1.8.0_241-b07)Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)#####04.部署 tomcat [root@oldboy-web-java-01 ~]# tar xf /app/tools/apache-tomcat-8.5.50.tar.gz -C /app/[root@oldboy-web-java-01 ~]# ln -s /app/apache-tomcat-8.5.50/ /app/tomcat####05 检查 jdk+tomcat[root@oldboy-web-java-01 ~]# /app/tomcat/bin/version.sh Using CATALINA_BASE: /app/tomcatUsing CATALINA_HOME: /app/tomcatUsing CATALINA_TMPDIR: /app/tomcat/tempUsing JRE_HOME: /app/jdkUsing CLASSPATH: /app/tomcat/bin/bootstrap.jar:/app/tomcat/bin/tomcat-juli.jarServer version: Apache Tomcat/8.5.50Server built: Dec 7 2019 19:19:46 UTCServer number: 8.5.50.0OS Name: LinuxOS Version: 4.18.0-80.11.2.el8_0.x86_64Architecture: amd64JVM Version: 1.8.0_241-b07JVM Vendor: Oracle CorporationWeb访问 10.0.0.0:8080 进行访问与测试

4. Tomcat目录结构

[root@web01 tomcat]# lltotal 92drwxr-xr-x 2 root root 4096 Dec 16 12:01 bin drwxr-xr-x 3 root root 198 Dec 16 12:08 confdrwxr-xr-x 2 root root 4096 Dec 16 12:01 lib #库文件 tomcat插件 drwxr-xr-x 2 root root 197 Dec 16 12:08 logs-rw-r--r-- 1 root root 1444 Sep 28 2015 NOTICE-rw-r--r-- 1 root root 6741 Sep 28 2015 RELEASE-NOTES-rw-r--r-- 1 root root 16204 Sep 28 2015 RUNNING.txtdrwxr-xr-x 2 root root 30 Dec 16 12:01 tempdrwxr-xr-x 7 root root 81 Sep 28 2015 webappsdrwxr-xr-x 3 root root 22 Dec 16 12:08 work

三、小试牛刀-部署简单Java页面

#应用war包 部署到 /app/tomcat/webapps/#tomcat 自动解压#tomcat 自动部署日志信息:

26-Aug-2021 10:58:13.011 信息 [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployWAR 正在部署web应用程序存档文件[/app/apache-tomcat-9.0.52/webapps/memtest.war]26-Aug-2021 10:58:13.089 信息 [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployWAR web应用程序存档文件[/app/apache-tomcat-9.0.52/webapps/memtest.war]的部署已在[77]ms内完成

四、Tomcat管理端

1. Tomcat管理端应用场景

2. 极速上手指南

注意事项(tomcat 9.0)

## 01 配置 tomcat 管理端 [root@static01 tomcat]# cat conf/tomcat-users.xml <?xml version="1.0" encoding="UTF-8"?><tomcat-users xmlns="http://tomcat.apache.org/xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd" version="1.0"> <role rolename="manager-gui"/> <role rolename="admin-gui"/> <user username="tomcat" password="1" roles="manager-gui,admin-gui"/></tomcat-users>## 02 重启tomcat ## 03 命令行测试 curl -u tomcat:1 http://127.0.0.1:8080/manager/status#注意:使用127.0.0.1 ## 04 开启tomcat默认的限制 /app/tomcat/webapps/host-manager/META-INF/context.xml /app/tomcat/webapps/manager/META-INF/context.xml [root@static01 tomcat]# sed -i.bak 's#127#//d+#g' /app/tomcat/webapps/host-manager/META-INF/context.xml /app/tomcat/webapps/manager/META-INF/context.xml[root@static01 tomcat]# find -name "context.xml" |xargs grep allow./webapps/host-manager/META-INF/context.xml: allow="/d+/./d+/./d+/./d+|::1|0:0:0:0:0:0:0:1" />./webapps/manager/META-INF/context.xml: allow="/d+/./d+/./d+/./d+|::1|0:0:0:0:0:0:0:1" />

3. 检查结果

五、Tomcat日志与进程信息

1. 进程信息

#ps命令查询 java进程信息[root@oldboy-web-java-01 ~]# ps -ef |grep java root 4112 1 1 11:43 pts/1 00:00:15 /app/jdk/bin/java -Djava.util.logging.config.file=/app/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /app/tomcat/bin/bootstrap.jar:/app/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/app/tomcat -Dcatalina.home=/app/tomcat -Djava.io.tmpdir=/app/tomcat/temp org.apache.catalina.startup.Bootstrap startroot 4199 4175 0 11:59 pts/0 00:00:00 grep --color=auto java[root@oldboy-web-java-01 ~]# /app/tomcat/bin/startup.sh /app/jdk/bin/java -Djava.util.logging.config.file=/app/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /app/tomcat/bin/bootstrap.jar:/app/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/app/tomcat -Dcatalina.home=/app/tomcat -Djava.io.tmpdir=/app/tomcat/temp org.apache.catalina.startup.Bootstrap start/app/tomcat_8081/app/tomcat_8082

2. Tomcat日志

catalina.out 主日志

###catalina.out # error 错误 # failed # exception 异常 # startup 或 finished 启动所需的时间# deploy 07-Feb-2020 12:03:16.039 INFO [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance.07-Feb-2020 12:03:16.039 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8080"]07-Feb-2020 12:03:16.046 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-8009"]07-Feb-2020 12:03:16.051 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina]07-Feb-2020 12:03:16.093 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]07-Feb-2020 12:03:16.098 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"]07-Feb-2020 12:03:16.100 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]07-Feb-2020 12:03:16.101 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]访问日志

223.104.2.165 - - [07/Feb/2020:12:10:00 +0800] "GET /tomcat.css HTTP/1.1" 200 5581223.104.2.165 - - [07/Feb/2020:12:10:00 +0800] "GET /tomcat.png HTTP/1.1" 200 5103223.104.2.165 - - [07/Feb/2020:12:10:00 +0800] "GET /bg-nav.png HTTP/1.1" 200 1401223.104.2.165 - - [07/Feb/2020:12:10:00 +0800] "GET /asf-logo-wide.svg HTTP/1.1" 200 27235223.104.2.165 - - [07/Feb/2020:12:10:00 +0800] "GET /bg-upper.png HTTP/1.1" 200 3103223.104.2.165 - - [07/Feb/2020:12:10:00 +0800] "GET /bg-middle.png HTTP/1.1" 200 1918223.104.2.165 - - [07/Feb/2020:12:10:00 +0800] "GET /bg-button.png HTTP/1.1" 200 713223.104.2.165 - - [07/Feb/2020:12:10:00 +0800] "GET /favicon.ico HTTP/1.1" 200 21630223.104.2.165 - - [07/Feb/2020:12:10:06 +0800] "GET / HTTP/1.1" 200 11215223.104.2.165 - - [07/Feb/2020:12:10:06 +0800] "GET /tomcat.css HTTP/1.1" 200 5581223.104.2.165 - - [07/Feb/2020:12:10:06 +0800] "GET /tomcat.png HTTP/1.1" 200 5103223.104.2.165 - - [07/Feb/2020:12:10:06 +0800] "GET /bg-nav.png HTTP/1.1" 200 1401223.104.2.165 - - [07/Feb/2020:12:10:06 +0800] "GET /asf-logo-wide.svg HTTP/1.1" 200 27235223.104.2.165 - - [07/Feb/2020:12:10:06 +0800] "GET /bg-upper.png HTTP/1.1" 200 3103223.104.2.165 - - [07/Feb/2020:12:10:06 +0800] "GET /bg-button.png HTTP/1.1" 200 713223.104.2.165 - - [07/Feb/2020:12:10:06 +0800] "GET /bg-middle.png HTTP/1.1" 200 1918223.104.2.165 - - [07/Feb/2020:12:10:06 +0800] "GET /favicon.ico HTTP/1.1" 200 21630223.104.2.165 - - [07/Feb/2020:12:10:11 +0800] "GET / HTTP/1.1" 200 11215223.104.2.165 - - [07/Feb/2020:12:10:11 +0800] "GET /tomcat.css HTTP/1.1" 304 -223.104.2.165 - - [07/Feb/2020:12:10:12 +0800] "GET /tomcat.png HTTP/1.1" 304 -223.104.2.165 - - [07/Feb/2020:12:10:12 +0800] "GET /asf-logo-wide.svg HTTP/1.1" 304 -223.104.2.165 - - [07/Feb/2020:12:10:12 +0800] "GET /bg-nav.png HTTP/1.1" 304 -223.104.2.165 - - [07/Feb/2020:12:10:12 +0800] "GET /bg-upper.png HTTP/1.1" 304 -223.104.2.165 - - [07/Feb/2020:12:10:12 +0800] "GET /bg-button.png HTTP/1.1" 304 -223.104.2.165 - - [07/Feb/2020:12:10:12 +0800] "GET /bg-middle.png HTTP/1.1" 304 -catalina.out和catalina.日期.log。

catalina.out在被切割后,内容不会被清空。

3. Tomcat日志格式

tomcat日志格式

#修改tomcat访问日志格式 pattern="%h %l %u %t &quot;%r&quot; %s %b %D &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;" /> <?xml version="1.0" encoding="UTF-8"?><Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <GlobalNamingResources> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> </GlobalNamingResources> <Service name="Catalina"> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b %D &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;" /> </Host> </Engine> </Service>


#server.xml#端口部分 ###8005 shutdown端口22 行: <Server port="8005" shutdown="SHUTDOWN">###tomcat shutdown端口 telnet/nc 连接到这个端口 输入暗号 tomcat将会关闭###8080 http协议端口 69 <Connector port="8080" protocol="HTTP/1.1" 70 connectionTimeout="20000" 71 redirectPort="8443" /> ###8009 ajp协议端口 与apache连接使用 115 116 #8009端口 是用来给 apache与tomcat进行连接使用 #现在 tomcat+nginx 可以把 这一行8009注释 提高tomcat性能 116 <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 提问:tomcat默认有几个端口 及作用 ?#tomcat管理端 相应的配置 ##管理端 实际生产环境 关闭 37 <GlobalNamingResources> 38 41 <Resource name="UserDatabase" auth="Container" 42 type="org.apache.catalina.UserDatabase" 43 description="User database that can be updated and saved" 44 factory="org.apache.catalina.users.MemoryUserDatabaseFactory" #指定管理端 密码文件 45 pathname="conf/tomcat-users.xml" /> 46 </GlobalNamingResources> #配置 tomcat 虚拟主机的内容 Nginx tomcat Server_name Host name 域名root appBase 站点目录#unpackWARs #自动解压war包 #autoDeploy 自动部署 把代码加载到jvm内存中 148 <Host name="localhost" appBase="webapps"149 unpackWARs="true" autoDeploy="true">150 151 153 156 157 #配置 日志 160 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" #日志文件 前缀是localhost_access_log #日志后缀161 prefix="access" suffix=".log" #日志 里面的格式 &quot html语言中的 双引号 #日志内容 类似于 log_format 162 pattern="%h %l %u %t &quot;%r&quot; %s %b" />163 164 </Host>#%h 客户端ip地址或者是域名 #%l (小写L) 远程用户 #%u 用户 Remote user that was authenticated (if any), else '-' (escaped if required)#%t 时间 日期和时间#&quot 双引号 #%r 请求起始行 $request #%s $status 状态码#%b 大小

六、Tomcat配置文件

[root@web03 /app/tomcat]# sed '//d;/^$/d;//d' conf/server.xml <?xml version="1.0" encoding="UTF-8"?>#8005端口是 shutdown端口 shutdown="" #关闭tomcat暗号 <Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />#tomcat 管理端配置 开始 <GlobalNamingResources> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> </GlobalNamingResources>#tomcat 管理端配置 结束 <Service name="Catalina"> #连接器 用户请求通过连接器 进入tomcat,然后经过tomcat处理. #8080是tomcat默认的web服务的端口 #8443tomcat+https <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> #配置tomcat https # defaultHost tomcat默认的主机(网站) <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> # Host name 域名 lidao.oldboylinux.com zrlog.oldboylinux.com ..# appBase=webapps 网站默认的站点目录(网站的代码)# Host name="zrlog.oldboylinux.com" appBase="/code/zrlog"# unpackWARs 自动解压war包 # autoDeploy 自动部署 <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> # 配置tomcat的访问日志. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"# 配置访问日志格式 #prefix 和suffix 日志文件名的格式 prefix="localhost_access_log" suffix=".txt"#日志里面的内容 pattern="%h %l %u %t &quot;%r&quot; %s %b %D " /> </Host> </Engine> </Service></Server>

七、部署Tomcat多虚拟主机

1. 环境准备

1、虚拟主机;2、一个网站;

#目标 浏览器访问 img.etiantian.org 显示 img 内容 浏览器访问 live.etiantian.org 显示 live 内容 浏览器访问 其他 。。。。 显示localhost默认内容

2. 配置与调试

mkdir -p /data/{live,img}/ROOT/ /var/log/tomcatecho live >/data/live/ROOT/index.jsp echo img > /data/img/ROOT/index.jsp


#tomcat访问的时候 uri小坑 ### 用户访问的域名如果包含路径(目录) tomcat会在站点目录下面匹配指定的目录然后匹配文件curl img.etiantian.org/oldboy/index.jsp --->站点目录下面的/oldboy/index.jsp ### 用户访问的url没有路径、目录 tomcat会在站点目录下面找ROOT/内容 进行匹配curl img.etiantian.org/index.jsp ---> 站点目录下面的/ROOT/index.jsp#tomcat虚拟主机#01 第1部分 设置默认的虚拟主机 <Engine name="Catalina" defaultHost="localhost">#02 第2个部分 虚拟主机的配置部分 #Host name="域名/localhost"#appBase="站点目录" 网站程序代码存放的目录 #/code/live#/code/img#/code/blog #/code/... <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">#directory 日志目录 /var/log/tomcat/ <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"#prefix="域名_access" suffix=".log" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b %D &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;" /> </Host> <Host name="live.oldboylinux.com" appBase="/code/live" unpackWARs="true" autoDeploy="true">#directory 日志目录 /var/log/tomcat/ <Valve className="org.apache.catalina.valves.AccessLogValve" directory="/var/log/tomcat/"#prefix="域名_access" suffix=".log" prefix="llive.oldboylinux.com_access" suffix=".log" pattern="%h %l %u %t &quot;%r&quot; %s %b %D &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;" /> </Host>配置了2个虚拟主机的tomcat

<Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="/var/log/tomcat/" prefix="localhost_access" suffix=".log" pattern="%h %l %u %t &quot;%r&quot; %s %b %D &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;" /> </Host> <Host name="live.oldboylinux.com" appBase="/code/live" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="/var/log/tomcat/" prefix="live_access" suffix=".log" pattern="%h %l %u %t &quot;%r&quot; %s %b %D &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;" /> </Host>#重启后检查结果[root@web03 /app/tomcat]# ll /var/log/tomcat/total 0-rw-r----- 1 root root 0 Aug 8 12:17 live_access.2021-08-08.log-rw-r----- 1 root root 0 Aug 8 12:17 localhost_access.2021-08-08.log#配置hosts解析 linux vim /etc/hosts 10.0.0.9 live.oldboylinux.comwindows : C:/Windows/System32/drivers/etc/hosts 10.0.0.9 live.oldboylinux.com#测试 live站点[root@web03 /app/tomcat]# mkdir /code/live/ROOT[root@web03 /app/tomcat]# echo live.oldboylinux.com web03 /code/live/ROOT/index.jsp live.oldboylinux.com web03 /code/live/ROOT/index.jsp[root@web03 /app/tomcat]# echo live.oldboylinux.com web03 > /code/live/ROOT/index.jsp [root@web03 /app/tomcat]# [root@web03 /app/tomcat]# curl live.oldboylinux.com:8080live.oldboylinux.com web03#测试 默认站点 echo this is default virtual host server > /app/tomcat/webapps/ROOT/index.jsp[root@web03 /app/tomcat]# curl 10.0.0.9:8080 this is default virtual host server [root@web03 /app/tomcat]# curl -H Host:lidao.oldboylinux.com 10.0.0.9:8080 this is default virtual host server[root@web03 /app/tomcat]#

3. 重看-tomcat处理请求流程

八、Java应用部署方式

1. 部署应用方式

如果开发给你的是war包,则把war包放入到 tomcat webapps自动解压、自动部署,开发给你源代码---maven-->war包;

如果开发给你的是jar包,相当于jar包里面已经集成了tomcat。

2. jar包运行

#jar运行演示java -jar dingding-sonar-1.0-SNAPSHOT.jar --server.port=8082

3. java开源软件-war包

4. 部署应用-zrlog

#01 tomcat <Host name="zrlog.etiantian.org" appBase="/data/blog/" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="/var/log/tomcat/" prefix="zrlog_access" suffix=".log" pattern="%h %l %u %t &quot;%r&quot; %s %b %D &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;" /> </Host> #02 数据库yum install -y mariadb-serversystemctl enable mariadbsystemctl start mariadb#初始的配置mysql_secure_installationSet root password? [Y/n] YNew password: Re-enter new password: Remove anonymous users? [Y/n] Y ... Success!Disallow root login remotely? [Y/n] Y ... Success!Remove test database and access to it? [Y/n] YReload privilege tables now? [Y/n] Y ... Success! Thanks for using MariaDB!#进入数据库##查看数据库show databases;##查看数据库用户信息select user,host from mysql.user;##创建zrlog用的数据库MariaDB [(none)]> create database zrlog charset utf8; Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> show databases; +--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || zrlog |+--------------------+4 rows in set (0.00 sec)##创建用户 admin 管理所有数据库 grant all on *.* to zrlog@'localhost' identified by '1'; grant all on *.* to zrlog@'%' identified by '1'; #03 .部署应用 把代码复制到/code/zrlog 自动解压,部署#04. 配置hosts解析10.0.0.9 zrlog.oldboylinux.com05: 接上面, web页面部署zrlog;

06: zrlog 连接数据库;

07: 检查 数据库内容(了解) 与用户是上传内容(必会)

select * from zrlog.log ;find /code/zrlog/ -type f -mmin -100#部署应用后 tomcat的日志 [WARN] 2021-06-02 11:08:46,902 com.zrlog.web.config.ZrLogConfig configPlugin - Not found lock file(/app/apache-tomcat-8.5.66/webapps/zrlog/WEB-INF/install.lock), Please visit the http://yourHostName:port/zrlog/install start installation02-Jun-2021 11:08:47.203 INFO [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/app/apache-tomcat-8.5.66/webapps/zrlog.war] has finished in [2,682] ms#准备数据库create database zrlog charset utf8;MariaDB [(none)]> select user,host from mysql.user;+------+-----------+| user | host |+------+-----------+| all | % || root | % || root | 127.0.0.1 || root | ::1 || root | db01 || root | localhost || root | web01 |+------+-----------+7 rows in set (0.00 sec)#web03 安装应用 让应用连接 数据库web页面安装zrlog;

检查数据库连接文件和用户上传的目录:

#数据库连接 [root@web03 /app/tomcat/webapps/zrlog]# cat ./WEB-INF/db.properties #This is a database configuration file#Wed Jun 02 11:14:44 CST 2021driverClass=com.mysql.cj.jdbc.Driveruser=allpassword=123456jdbcUrl=jdbc/:mysql/://172.16.1.51/:3306/zrlog?characterEncoding/=UTF-8&allowPublicKeyRetrieval/=true&useSSL/=false&serverTimezone/=GMT#用户上传 http://10.0.0.9:8080/zrlog/attached/image/20210602/20210602111945_677.png

九、Tomcat 3种工作模式:bio、nio、apr

1. IO模型区别

2. 查看当前使用的io模型

查看日志

查看管理端

3. 修改IO模型

nio

protocol="org.apache.coyote.http11.Http11Nio2Protocol"#server.xml 中 修改 8080 <Connector port="8080" protocol="org.apache.coyote.http11.Http11Nio2Protocol" connectionTimeout="20000" redirectPort="8443" />[root@web03 /app/tomcat]# grep -ni nio2 conf/server.xml69: <Connector port="8080" protocol="org.apache.coyote.http11.Http11Nio2Protocol"查看修改结果-catalina.out日志

17-Dec-2019 10:46:33.106 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio2-8080"]查看修改结果-tomcat管理端

apr

#安装apr环境yum -y install apr apr-devel tomcat-native#修改8080&8009端口对应的server.xmlprotocol="org.apache.coyote.http11.Http11Nio2Protocol"把Nio2 修改为Apr protocol="org.apache.coyote.http11.Http11AprProtocol"17-Dec-2019 10:59:41.605 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]17-Dec-2019 10:59:41.621 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 3982 ms不知如何自学?遇到问题不能及时解决?缺乏实战经验?如果你也有以上问题,可以了解下5天集训营课程!

训练营开课周期:2周1次,每晚20:00开始,由浅入深、通俗易懂,手把手带你掌握Linux,只要你认真听,100%可以学会!

Day1 细说Linux基础命令

Day2 手把手带你搭建企业网盘、博客框架!

Day3 带你认识Linux系统(前景、岗位、发展路线)

Day4 亿级PV高并发网站架构精讲

Day5 百亿级PV网站架构精讲

集训营主讲老师:老男孩IT教育创始人,老男孩老师 ,中国IT领域实战心理学思想体系创始人,13年+创业经历,互联网顶尖Linux运维及大规模集群架构专家,曾受邀做客CCTV、网易、教育在线等栏目,著有多本IT畅销图书及职场高薪秘笈指南。

报名后可享受以下服务:

完课后可获得以下福利:

(如果你对集训营感兴趣,评论区回复"666" or 私信我)

码字实属不易,如果对你有帮助的话,点个赞收个藏,给作者一个鼓励。

更多精彩内容,请关注公众号【老男孩Linux】


关键词:足够,收藏,技术

74
73
25
news

版权所有© 亿企邦 1997-2025 保留一切法律许可权利。

为了最佳展示效果,本站不支持IE9及以下版本的浏览器,建议您使用谷歌Chrome浏览器。 点击下载Chrome浏览器
关闭