配置

一、环境配置

  1. 根据 tomcat 版本,在 bin/catalina.sh 中配置不同的 JAVA_HOME 路径,实际情况个根据安装的 JDK HOME 路径有关
  2. 1.7
  3. JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home"
  4. 1.8
  5. JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home"

* web.xml

  1. seesion 超时时间, 单位分钟
  2. <session-config>
  3. <session-timeout>600</session-timeout>
  4. </session-config>

tomcat-users.xml

访问 manager 的用户

  1. <tomcat-users>
  2. <role rolename="manager"/>
  3. <user username="admin" password="admin" roles="manager"/>
  4. <role rolename="manager-gui"/>
  5. <user username="admin" password="admin" roles="manager-gui"/>
  6. </tomcat-users>

* server.xml

  • 同一个 tomcat 服务器, N 个容器配置
  • 多台 tomcat 服务器, 不同容器配置也是类似方法
  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. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <!-- Note: A "Server" is not itself a "Container", so you may not
  17. define subcomponents such as "Valves" at this level.
  18. Documentation at /docs/config/server.html
  19. -->
  20. <!-- 不同服务器要区分开这个端口 -->
  21. <Server port="8005" shutdown="SHUTDOWN">
  22. <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  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. <!-- Global JNDI resources
  35. Documentation at /docs/jndi-resources-howto.html
  36. -->
  37. <GlobalNamingResources>
  38. <!-- Editable user database that can also be used by
  39. UserDatabaseRealm to authenticate users
  40. -->
  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>
  47. <!-- 第 1 个 --->
  48. <Service name="Catalina1">
  49. <!--The connectors can use a shared executor, you can define one or more named thread pools-->
  50. <!--
  51. <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
  52. maxThreads="150" minSpareThreads="4"/>
  53. -->
  54. <!-- A "Connector" represents an endpoint by which requests are received
  55. and responses are returned. Documentation at :
  56. Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
  57. Java AJP Connector: /docs/config/ajp.html
  58. APR (HTTP/AJP) Connector: /docs/apr.html
  59. Define a non-SSL HTTP/1.1 Connector on port 8080
  60. -->
  61. <Connector port="8080" protocol="HTTP/1.1"
  62. connectionTimeout="20000"
  63. redirectPort="8443" />
  64. <!-- A "Connector" using the shared thread pool-->
  65. <!--
  66. <Connector executor="tomcatThreadPool"
  67. port="8080" protocol="HTTP/1.1"
  68. connectionTimeout="20000"
  69. redirectPort="8443" />
  70. -->
  71. <!-- Define a SSL HTTP/1.1 Connector on port 8443
  72. This connector uses the BIO implementation that requires the JSSE
  73. style configuration. When using the APR/native implementation, the
  74. OpenSSL style configuration is required as described in the APR/native
  75. documentation -->
  76. <!--
  77. <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
  78. maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
  79. clientAuth="false" sslProtocol="TLS" />
  80. -->
  81. <!-- Define an AJP 1.3 Connector on port 8009 -->
  82. <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
  83. <!-- An Engine represents the entry point (within Catalina) that processes
  84. every request. The Engine implementation for Tomcat stand alone
  85. analyzes the HTTP headers included with the request, and passes them
  86. on to the appropriate Host (virtual host).
  87. Documentation at /docs/config/engine.html -->
  88. <!-- You should set jvmRoute to support load-balancing via AJP ie :
  89. <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
  90. -->
  91. <Engine name="Catalina1" defaultHost="localhost">
  92. <!--For clustering, please take a look at documentation at:
  93. /docs/cluster-howto.html (simple how to)
  94. /docs/config/cluster.html (reference documentation) -->
  95. <!--
  96. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  97. -->
  98. <!-- Use the LockOutRealm to prevent attempts to guess user passwords
  99. via a brute-force attack -->
  100. <Realm className="org.apache.catalina.realm.LockOutRealm">
  101. <!-- This Realm uses the UserDatabase configured in the global JNDI
  102. resources under the key "UserDatabase". Any edits
  103. that are performed against this UserDatabase are immediately
  104. available for use by the Realm. -->
  105. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  106. resourceName="UserDatabase"/>
  107. </Realm>
  108. <Host name="localhost" appBase="webapps/Catalina1"
  109. unpackWARs="true" autoDeploy="true">
  110. <!-- SingleSignOn valve, share authentication between web applications
  111. Documentation at: /docs/config/valve.html -->
  112. <!--
  113. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  114. -->
  115. <!-- Access log processes all example.
  116. Documentation at: /docs/config/valve.html
  117. Note: The pattern used is equivalent to using pattern="common" -->
  118. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs/Catalina1"
  119. prefix="localhost_access_log." suffix=".txt"
  120. pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  121. </Host>
  122. </Engine>
  123. </Service>
  124. <!-- 第 2 个 --->
  125. <Service name="Catalina2">
  126. <!--The connectors can use a shared executor, you can define one or more named thread pools-->
  127. <!--
  128. <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
  129. maxThreads="150" minSpareThreads="4"/>
  130. -->
  131. <!-- A "Connector" represents an endpoint by which requests are received
  132. and responses are returned. Documentation at :
  133. Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
  134. Java AJP Connector: /docs/config/ajp.html
  135. APR (HTTP/AJP) Connector: /docs/apr.html
  136. Define a non-SSL HTTP/1.1 Connector on port 8080
  137. -->
  138. <Connector port="8081" protocol="HTTP/1.1"
  139. connectionTimeout="20000"
  140. redirectPort="8444" />
  141. <!-- A "Connector" using the shared thread pool-->
  142. <!--
  143. <Connector executor="tomcatThreadPool"
  144. port="8080" protocol="HTTP/1.1"
  145. connectionTimeout="20000"
  146. redirectPort="8443" />
  147. -->
  148. <!-- Define a SSL HTTP/1.1 Connector on port 8443
  149. This connector uses the BIO implementation that requires the JSSE
  150. style configuration. When using the APR/native implementation, the
  151. OpenSSL style configuration is required as described in the APR/native
  152. documentation -->
  153. <!--
  154. <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
  155. maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
  156. clientAuth="false" sslProtocol="TLS" />
  157. -->
  158. <!-- Define an AJP 1.3 Connector on port 8009 -->
  159. <Connector port="8010" protocol="AJP/1.3" redirectPort="8444" />
  160. <!-- An Engine represents the entry point (within Catalina) that processes
  161. every request. The Engine implementation for Tomcat stand alone
  162. analyzes the HTTP headers included with the request, and passes them
  163. on to the appropriate Host (virtual host).
  164. Documentation at /docs/config/engine.html -->
  165. <!-- You should set jvmRoute to support load-balancing via AJP ie :
  166. <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
  167. -->
  168. <Engine name="Catalina2" defaultHost="localhost">
  169. <!--For clustering, please take a look at documentation at:
  170. /docs/cluster-howto.html (simple how to)
  171. /docs/config/cluster.html (reference documentation) -->
  172. <!--
  173. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  174. -->
  175. <!-- Use the LockOutRealm to prevent attempts to guess user passwords
  176. via a brute-force attack -->
  177. <Realm className="org.apache.catalina.realm.LockOutRealm">
  178. <!-- This Realm uses the UserDatabase configured in the global JNDI
  179. resources under the key "UserDatabase". Any edits
  180. that are performed against this UserDatabase are immediately
  181. available for use by the Realm. -->
  182. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  183. resourceName="UserDatabase"/>
  184. </Realm>
  185. <Host name="localhost" appBase="webapps/Catalina2"
  186. unpackWARs="true" autoDeploy="true">
  187. <!-- SingleSignOn valve, share authentication between web applications
  188. Documentation at: /docs/config/valve.html -->
  189. <!--
  190. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  191. -->
  192. <!-- Access log processes all example.
  193. Documentation at: /docs/config/valve.html
  194. Note: The pattern used is equivalent to using pattern="common" -->
  195. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs/Catalina2"
  196. prefix="localhost_access_log." suffix=".txt"
  197. pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  198. </Host>
  199. </Engine>
  200. </Service>
  201. </Server>