tomcat

2017-01-05  本文已影响29人  zjlearn

[TOC]

简介

Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目;Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器。

安装

一般配置环境变量
$CATALINA_HOME为安装tomcat的主目录。
Tomcat也可以通过配置
*$CATALINA_BASE **配置多个实例

目录结构

配置

下面围绕server.xml文件对tomcat的配置进行描述。
tomcat的配置放置在格式化的XML 文件server.xml中, XML文件中的元素和值时大小写敏感的。
官方的文档如下:
官方参考:http://tomcat.apache.org/tomcat-9.0-doc/config/index.html
下面是server.xml中的层次结构

<?xml version="1.0" encoding="utf-8"?>

<Server> 
  <Service> 
     <Connector/>  
    <Connector/>  
    <Engine> 
      <Host> 
        <Context></Context> 
      </Host> 
    </Engine> 
  </Service> 
</Server>

下面时官方文档中关于tomcat文件中的相对应的描述:

server

官方给出的解释是: A Server element represents the entire Catalina servlet container。因此器作为顶层元素,其属性代表了servlet容器的整体特点。
以下时Server支持的属性:

<Server port="8005" shutdown="SHUTDOWN">

Service

官方中对于Service的描述如下:
A Service element represents the combination of **one or more Connector ** components that share a single Engine component for processing incoming requests. One or more Service elements may be nested inside a Server element.
Service支持以下的属性:

<Service name=”Catalina”>
<Service name=”Apache”>

Service不支持定义其他属性

Executor

Ex ecutor主要代表了可以在tomcat组件之间共享的线程池,其于java并发中的额概念相似。

Engine

The Engine element represents the entire request processing machinery associated with a particular Catalina Service. It receives and processes all requests from one or more Connectors, and returns the completed response to the Connector for ultimate transmission back to the client.

Exactly one Engine element MUST be nested inside a Service element, following all of the corresponding Connector elements associated with this Service.
Engine 支持以下的属性:

注: Tomcat 启动后, Engine 、 Host 、 Context 会启动一个后台线程,定期调用backgroundProcessor方法。backgroundProcessor方法主要用于重新加载 Web 应用程序的类文件和资源、扫描 Session 过期

<Enginename=”Catalina” defaultHost=”localHost” debug=”0”>

运行原理

细节待定

参数

当使用脚本运行tomcat时,可以通过设置环境变量JAVA_OPTS来配置tomcat的运行
例如:

export JAVA_OPTS="-server -Xms2048m -Xmx2048m"

其中Xmx设置JVM最大可以使用内存,Xms设置初始的JVM可以使用的内存的大小。

web应用标准目录

文档:http://tomcat.apache.org/tomcat-9.0-doc/appdev/deployment.html
对web应用程序的标准部署进行了描述。

参考资料

官方文档:http://tomcat.apache.org/
书籍: 深入剖析tomcat
博客:http://www.tuicool.com/articles/qINNZf

上一篇 下一篇

猜你喜欢

热点阅读