新网Logo
首页>虚机资讯>

Tomcat学习系列之二了解tomcat的目录以及常用配置

登录 注册

Tomcat学习系列之二了解tomcat的目录以及常用配置

  • 来源:
  • 更新日期:2018-05-03

摘要:一,目录结构 1, 目录浏览: [root@ishare-testing apache-tomcat-7.0.20]# tree -L 1 ├── bin ├── conf ├── lib ├── LICENSE ├── logs ├── NOTICE ├── RELEASE-NOTES ├── RUNNING.txt ├── tem

一,目录结构

1, 目录浏览:

y2vzmvxcck4.jpg

[root@ishare-testing apache-tomcat-7.0.20]# tree -L 1 ├── bin ├── conf ├── lib ├── LICENSE ├── logs ├── NOTICE ├── RELEASE-NOTES ├── RUNNING.txt ├── temp ├── webapps └── work

2,常用目录:

bin目录:一些启动,关闭和其他的脚本程序,扩展名为sh的为类unix. bat扩展名是windows环境下的.win32缺少某些功能,所以bat脚本有几个额外的

conf - 存放着tomcat的配置文件和配置相关的dtd文件,其中最重要的server.xml文件,它是tomcat的主配置文件.

logs- 存放tomcat的l日志目录.

webapps-默认的你的webapp的存放位置,这个可以在server.xml可以配置.

lib - 是加载的jar包,lib库.

work - 存放java代码的编译class文件.

二,配置文件

tomcat的配置文件放在conf目录里,其中server.xml是tomcat的主配置文件.

tomcat的配置文件是xml文件,xml文件以标签开始和结尾对应的,其中<!-- -->是注释.

 

了解server.xml文件.

1 <?xml version=\'1.0\' encoding=\'utf-8\'?> 2 <!-- 3 Licensed to the Apache Software Foundation (ASF) under one or more 4 contributor license agreements. See the NOTICE file distributed with 5 this work for additional information regarding copyright ownership. 6 The ASF licenses this file to You under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with 8 the License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 See the License for the specific language governing permissions and 16 limitations under the License. 17 --> 18 <!-- Note: A "Server" is not itself a "Container", so you may not 19 define subcomponents such as "Valves" at this level. 20 Documentation at /docs/config/server.html 21 --> 22 <Server port="8005" shutdown="SHUTDOWN"> 监听关闭tomcat的命令的端口,telent 进入8005,输入SHUTDOWN即可关闭tomcat. 23 <!-- Security listener. Documentation at /docs/config/listeners.html 24 <Listener className="org.apache.catalina.security.SecurityListener" /> 25 --> 26 <!--APR library loader. Documentation at /docs/apr.html --> 27 <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 28 <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html --> 29 <Listener className="org.apache.catalina.core.JasperListener" /> 30 <!-- Prevent memory leaks due to use of particular java/javax APIs--> 31 <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> 32 <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 33 <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> 34 35 <!-- Global JNDI resources 36 Documentation at /docs/jndi-resources-howto.html 37 --> 38 <GlobalNamingResources> 39 <!-- Editable user database that can also be used by 40 UserDatabaseRealm to authenticate users 41 --> 42 <Resource name="UserDatabase" auth="Container" 43 type="org.apache.catalina.UserDatabase" 44 description="User database that can be updated and saved" 45 factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 46 pathname="conf/tomcat-users.xml" /> 47 </GlobalNamingResources> 48 49 <!-- A "Service" is a collection of one or more "Connectors" that share 50 a single "Container" Note: A "Service" is not itself a "Container", 51 so you may not define subcomponents such as "Valves" at this level. 52 Documentation at /docs/config/service.html 53 --> 54 <Service name="Catalina"> 55 56 <!--The connectors can use a shared executor, you can define one or more named thread pools--> 57 <!-- 58 <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" 59 maxThreads="150" minSpareThreads="4"/> 60 --> 61 62 63 <!-- A "Connector" represents an endpoint by which requests are received 64 and responses are returned. Documentation at : 65 Java HTTP Connector: /docs/config/http.html (blocking & non-blocking) 66 Java AJP Connector: /docs/config/ajp.html 67 APR (HTTP/AJP) Connector: /docs/apr.html 68 Define a non-SSL HTTP/1.1 Connector on port 8080 69 --> 70 <Connector port="8080" protocol="HTTP/1.1" 71 connectionTimeout="20000" 72 redirectPort="8443" /> 在端口号8080处侦听来自客户browser的HTTP1.1请求 minProcessors : 该Connector先创建5个线程等待客户请求, 每个请求由一个线程负责 maxProcessors : 当现有的线程不够服务客户请求时,若线程总数不足75个,则创建新线程来处理请求 acceptCount : 当现有线程已经达到最大数75时,为客户请求排队 当队列中请求数超过100时,后来的请求返回Connection refused 错误 redirectport : 当客户请求是https时,把该请求转发到端口8443去 . 73 <!-- A "Connector" using the shared thread pool--> 74 <!-- 75 <Connector executor="tomcatThreadPool" 76 port="8080" protocol="HTTP/1.1" 77 connectionTimeout="20000" 78 redirectPort="8443" /> 79 --> 80 <!-- Define a SSL HTTP/1.1 Connector on port 8443 81 This connector uses the JSSE configuration, when using APR, the 82 connector should be using the OpenSSL style configuration 83 described in the APR documentation --> 84 <!-- 85 <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" 86 maxThreads="150" scheme="https" secure="true" 87 clientAuth="false" sslProtocol="TLS" /> 配置https协议的,类似port=8080 88 --> 89 90 <!-- Define an AJP 1.3 Connector on port 8009 --> 91 <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 92 93 94 <!-- An Engine represents the entry point (within Catalina) that processes 95 every request. The Engine implementation for Tomcat stand alone 96 analyzes the HTTP headers included with the request, and passes them 97 on to the appropriate Host (virtual host). 98 Documentation at /docs/config/engine.html --> 99 100 <!-- You should set jvmRoute to support load-balancing via AJP ie : 101 <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1"> 102 --> 103 <Engine name="Catalina" defaultHost="localhost"> 104 处理http的请求头,定义了默认的虚拟接的名字"localhost" 105 <!--For clustering, please take a look at documentation at: 106 /docs/cluster-howto.html (simple how to) 107 /docs/config/cluster.html (reference documentation) --> 108 <!-- 109 <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> 110 --> 111 112 <!-- Use the LockOutRealm to prevent attempts to guess user passwords 113 via a brute-force attack --> 114 <Realm className="org.apache.catalina.realm.LockOutRealm"> 115 <!-- This Realm uses the UserDatabase configured in the global JNDI 116 resources under the key "UserDatabase". Any edits 117 that are performed against this UserDatabase are immediately 118 available for use by the Realm. --> 119 <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 120 resourceName="UserDatabase"/> 121 </Realm> 122 123 <Host name="localhost" appBase="webapps" 124 unpackWARs="true" autoDeploy="true"> 125 配置的tomcat的webapps的信息,可以建立多个host的,相当于apache 的虚拟主机(virtualHost). name是虚拟主机名.配置多虚拟机,后面将详细总结. 126 <!-- SingleSignOn valve, share authentication between web applications 127 Documentation at: /docs/config/valve.html --> 128 <!-- 129 <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> 130 --> 131 132 <!-- Access log processes all example. 133 Documentation at: /docs/config/valve.html 134 Note: The pattern used is equivalent to using pattern="common" --> 135 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 136 prefix="localhost_access_log." suffix=".txt" 137 pattern="%h %l %u %t &quot;%r&quot; %s %b" /> 配置Host的响应的访问日志文件 138 139 </Host> 140 </Engine> 141 </Service> 142 </Server>