Tomcat介绍
1 startup.bat
1 | ::注解说明 |
2 | rem Guess CATALINA_HOME if not defined |
3 | set "CURRENT_DIR=%cd%" |
4 | :: 若不存在CATALINA_HOME就跳转到goHome标签处 |
5 | if not "%CATALINA_HOME%" == "" goto gotHome |
6 | set "CATALINA_HOME=%CURRENT_DIR%" |
7 | :: 若存在CATALINA_HOME就跳转到okHome标签处 |
8 | if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome |
9 | :: 切换到tomcat的根目录,并将CATALINA_HOME设置成根目录路径 |
10 | cd .. |
11 | set "CATALINA_HOME=%cd%" |
12 | cd "%CURRENT_DIR%" |
13 | :gotHome |
14 | if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome |
15 | echo The CATALINA_HOME environment variable is not defined correctly |
16 | echo This environment variable is needed to run this program |
17 | goto end |
18 | :okHome |
19 | :: 将catalina所在路径赋予EXECUTABLE变量 |
20 | set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat" |
21 | |
22 | rem Check that target executable exists |
23 | if exist "%EXECUTABLE%" goto okExec |
24 | echo Cannot find "%EXECUTABLE%" |
25 | echo This file is needed to run this program |
26 | goto end |
27 | :okExec |
28 | |
29 | rem Get remaining unshifted command line arguments and save them in the |
30 | set CMD_LINE_ARGS= |
31 | :setArgs |
32 | if ""%1""=="""" goto doneSetArgs |
33 | set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1 |
34 | shift |
35 | goto setArgs |
36 | :doneSetArgs |
37 | |
38 | call "%EXECUTABLE%" start %CMD_LINE_ARGS% |
39 | |
40 | :end |
总结: 当CATALINA_HOME不存在时,会根据startup.bat文件路径上级作为tomcat的根路径并赋予CATALINA_HOME,之后便定位使用。所以,当要布署多个tomcat时,最好不要在环境变量里面设置tomcat的
CATALINA_HOME值
- stop.bat 同startup.bat
- catalina.bat 同startup.bat
我们可以显式指定tomcat相关命令所在路径
1 | set CATALINA_HOME=C:\tomcatServer |
2 | set CATALINA_BASE=C:\tomcatInstanceOne |
3 | C:\tomcatServer\bin\startup.bat |
2. 布署多个tomcat实例
**conf\server.xml**
1 |
|
2 | <!--服务器 shutdown端口设置--> |
3 | <Server port="8005" shutdown="SHUTDOWN"> |
4 | <!--监听器--> |
5 | <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> |
6 | <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> |
7 | <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> |
8 | <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> |
9 | <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> |
10 | <!--全局名称空间资源配置--> |
11 | <GlobalNamingResources> |
12 | <Resource name="UserDatabase" auth="Container" |
13 | type="org.apache.catalina.UserDatabase" |
14 | description="User database that can be updated and saved" |
15 | factory="org.apache.catalina.users.MemoryUserDatabaseFactory" |
16 | pathname="conf/tomcat-users.xml" /> |
17 | </GlobalNamingResources> |
18 | <!--服务--> |
19 | <Service name="Catalina"> |
20 | <!--http协议--> |
21 | <Connector port="8080" protocol="HTTP/1.1" |
22 | connectionTimeout="20000" |
23 | redirectPort="8443" /> |
24 | <!--AJP协议:Apache JServ Protocol--> |
25 | <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> |
26 | <!--引擎名: 在tomcat加载过程中会使用--> |
27 | <Engine name="Catalina" defaultHost="localhost"> |
28 | <!--存储了资源与访问信息--> |
29 | <Realm className="org.apache.catalina.realm.LockOutRealm"> |
30 | <Realm className="org.apache.catalina.realm.UserDatabaseRealm" |
31 | resourceName="UserDatabase"/> |
32 | </Realm> |
33 | <!--主机: web应用所放位置--> |
34 | <Host name="localhost" appBase="webapps" |
35 | unpackWARs="true" autoDeploy="true"> |
36 | <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" |
37 | prefix="localhost_access_log" suffix=".txt" |
38 | pattern="%h %l %u %t "%r" %s %b" /> |
39 | </Host> |
40 | </Engine> |
41 | </Service> |
42 | </Server> |
下图是server中的server service engine host context的关系 ,及连接时所用的协议原理图
所要更改的选项
- shutdown
- protocal
- http
- ajp
1 | <connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> |
2 | <server port="8005" shutdown="SHUTDOWN"/> |
3 | <connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> |