tomcat相关知识总结(基础)

tomcat的架构图

整体的结构框图如上:http是B/S模型,AJP是S/S模型协议。

  1. 整个tomcat是一个server服务器,里面可以包含多个service。
  2. 一个service就是一个完整的服务,包含connet(监听器,可以使多个)、engine(处理引擎 只能是一个),connect监听连接,处理后创建请求体与返回体。交个engine处理
  3. 引擎容器可以包含多个虚拟主机,只有一个默认主机。
  4. host容器:代表一个站点。其实就是一个主机,有可能是虚拟的。包含多个应用容器。
  5. context容器代表一个应用容器。

tomcat配置文件说明

tomcat目录结构:

  •   |---bin:存放启动和关闭tomcat脚本
  •   |---conf:存放不同的配置文件(server.xml和web.xml);
  •   |---doc:存放Tomcat文档;
  •   |---lib/japser/common:存放Tomcat运行需要的库文件(JARS);
  •   |---logs:存放Tomcat执行时的LOG文件;
  •   |---src:存放Tomcat的源代码;
  •   |---webapps:Tomcat的主要Web发布目录(包括应用程序示例);
  •   |---work:存放jsp编译后产生的class文件;

Tomcat配置文件: 我们打开con文件夹可以看到Tomcat的配置文件:

  1. server.xml: Tomcat的主配置文件,包含Service, Connector, Engine, Realm, Valve, Hosts主组件的相关配置信息;
  2. web.xml:遵循Servlet规范标准的配置文件,用于配置servlet,并为所有的Web应用程序提供包括MIME映射等默认配置信息; 
  3. tomcat-user.xml:Realm认证时用到的相关角色、用户和密码等信息;Tomcat自带的manager默认情况下会用到此文件;在Tomcat中添加/删除用户,为用户  指定角色等将通过编辑此文件实现;
  4. catalina.policy:Java相关的安全策略配置文件,在系统资源级别上提供访问控制的能力;
  5. catalina.properties:Tomcat内部package的定义及访问相关控制,也包括对通过类装载器装载的内容的控制;Tomcat在启动时会事先读取此文件的相关设置;
  6. logging.properties: Tomcat6通过自己内部实现的JAVA日志记录器来记录操作相关的日志,此文件即为日志记录器相关的配置信息,可以用来定义日志记录的组  件级别以及日志文件的存在位置等;
  7. context.xml:所有host的默认配置信息;

tomcat其他知识点1:配置方式

tomcat的配置方式一般有自动部署与手动部署方式。应用的配置方式主要有两个一个path与docBase属性,

  1. 自动配置的时候,系统会扫面webapps下的应用目录,当有一个app1的时候会创建一个app1 的path路径,当与到ROOT的时候,设置为主机的默认目录;系统也会扫描config/Catalina\localhost/***.xml文件,同理也会创建一个***的path,当***的应用不在webapp下面的时候,需要docBase指出。例如配置文件的context增加docBase。
  2. 手动配置的静态配置,在server.XML中增加注意这种配置方式,server.xml文件不能进行在动加载,在改动的时候,需要重新启动。 3.另外一种方式。其实就是另外两个方式的另外一种实现。就是通过设置CATALANA_BASE的环境变量重新采用一组新的配置文件。idea 就是采用这样方式先的配置。

tomcat其他知识点1:自动部署。

自动部署就是自动匹配web应用于uri的路径信息,找到正确的servlet。设置应用的path的过程与静态描述如下。

The automatic deployment process identifies new and/or modified web applications using the following search order:

  1. Web applications with a context.xml file located in the Host's configBase.
  2. Web applications with a WAR file located in the Host's appBase that have not already been identified during the scan for context.xml files.
  3. Web applications with a directory located in the Host's appBase that have not already been identified during the scans for context.xml and/or WAR files.

当不在webapps的目录下的时候需要设置docBase

  1. When using automatic deployment, the docBase defined by an XML Context file should be outside of the appBase directory. If this is not the case, difficulties may be experienced deploying the web application or the application may be deployed twice. The deployIgnore attribute can be used to avoid this situation.

  2. Note that if you are defining contexts explicitly in server.xml, you should probably turn off automatic application deployment or specify deployIgnore carefully. Otherwise, the web applications will each be deployed twice, and that may cause problems for the applications.

context的配置目录

context有私有文件与默认配置文件,默认配置文件是为host下面的所有的应用共同应用的,私有的是某个应用专用的。私有配置的文件优先级高,可以覆盖公共的文件。

Individual Context elements may be explicitly defined:

  1. In an individual file at /META-INF/context.xml inside the application files. Optionally (based on the Host's copyXML attribute) this may be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to application's base file name plus a ".xml" extension.
  2. In individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The context path and version will be derived from the base name of the file (the file name less the .xml extension). This file will always take precedence over any context.xml file packaged in the web application's META-INF directory.
  3. Inside a Host element in the main conf/server.xml.

Default Context elements may be defined that apply to multiple web applications. Configuration for an individual web application will override anything configured in one of these defaults. Any nested elements, e.g. elements, that are defined in a default Context will be created once for each Context to which the default applies. They will not be shared between Context elements.

  1. In the $CATALINA_BASE/conf/context.xml file: the Context element information will be loaded by all web applications.
  2. In the $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all web applications of that host.

With the exception of server.xml, files that define Context elements may only define a single Context element.

参考: 官网:官网的东西是最为经典的,纯粹的,详细的
详解Tomcat 配置文件server.xml :写的很清晰,是经过思索的文字,并且参考了官网很多内容,值得推荐
tomcat的组成:借鉴了一幅图。

转载于:https://juejin.im/post/5cfe306b6fb9a07efb697ab1

猜你喜欢

转载自blog.csdn.net/weixin_34221112/article/details/91459996