我的架构梦:(十五)Tomcat 服务器核心配置详解

Tomcat 服务器核心配置详解

    • 一、主要标签结构
    • 二、Server 标签
    • 三、Service 标签
    • 四、Executor 标签
    • 五、Connector 标签
    • 六、Engine 标签
    • 七、Host 标签
    • 八、Context 标签

注意:

  • Tomcat 作为服务器的配置,主要是 conf/server.xml 文件的配置;
  • server.xml中包含了 Servlet容器的相关配置,即 Catalina 的配置;
  • Xml 文件的讲解主要是标签的使用。

一、主要标签结构

 
<Server>
	
	<Listener/> 
	 
	<GlobalNamingResources/> 
	
    <Service/>
Server>

二、Server 标签


<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">
  	...
  Service>
Server>

三、Service 标签

 

<Service name="Catalina">
	...
Service>

四、Executor 标签


<Executor name="commonThreadPool"
	namePrefix="thread-exec-"
	maxThreads="200"
	minSpareThreads="100"
	maxIdleTime="60000"
	maxQueueSize="Integer.MAX_VALUE" prestartminSpareThreads="false"
	threadPriority="5" className="org.apache.catalina.core.StandardThreadExecutor"/>

五、Connector 标签

Connector 标签用于创建链接器实例

默认情况下,server.xml 配置了两个链接器,一个支持HTTP协议,一个支持AJP协议

大多数情况下,我们并不需要新增链接器配置,只是根据需要对已有链接器进行优化。


 
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

可以使用共享线程池

<Connector port="8080" 
	protocol="HTTP/1.1" 
	executor="commonThreadPool" 
	maxThreads="1000" 
    minSpareThreads="100" 
    acceptCount="1000" 
    maxConnections="1000" 
    connectionTimeout="20000" 
    compression="on" 
    compressionMinSize="2048" 
    disableUploadTimeout="true" 
    redirectPort="8443" 
    URIEncoding="UTF-8" />

六、Engine 标签

Engine 表示 Servlet 引擎


<Engine name="Catalina" defaultHost="localhost">
	...
Engine>

七、Host 标签

Host 标签用于配置一个虚拟主机

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> 
	...
Host>

八、Context 标签

Context 标签用于配置一个Web应用,如下:

<Host name="www.abc.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
	
	<Context docBase="/Users/yingdian/web_demo" path="/web3">Context>
	
	<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 	
		prefix="localhost_access_log" suffix=".txt" 
		pattern="%h %l %u %t "%r" %s %b" />
Host>

你可能感兴趣的:(我的架构梦)