目录
  1. 1. 前言
  2. 2. 操作方法
一个tomcat同时部署多个项目

前言

一个tomcat部署多个项目常用的方法是将所有的项目放置在webapps里面,共用同一个端口,各项目根据项目名进行区分。如果多个项目有启动先后顺序,这样的做法就显得不合适,因为tomcat启动是根据项目名称字母顺序来启动。网上有种做法,在conf\Catalina\localhost文件夹下建立需要首先启动的项目相应文件,如果是两个项目没有问题,但多个项目仍然不方便控制。实用的做法是定义多个service标签,各项目使用不同的端口号。

操作方法

1、conf\server.xml定义多个service,需要注意各service端口、redirectPort端口和appBase对应文件夹都要不一样

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<Service name="Catalina">
<Connector port="8700" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" maxThreads="500" acceptCount="500"
compression="on" URIEncoding="UTF-8"
compressionMinSize="2048"
maxPostSize="-1"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/plain,text/css,
text/javascript,text/json,application/x-javascript,
application/javascript,application/json"/>
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="/kbs-hosp-srv" docBase="/app/project/kbs-hosp-srv.war" reloadable="false" debug="0" />
</Host>
</Engine>
</Service>

<Service name="Catalina">
<Connector port="8701" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8444" maxThreads="500" acceptCount="500"
compression="on" URIEncoding="UTF-8"
compressionMinSize="2048"
maxPostSize="-1"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/plain,text/css,
text/javascript,text/json,application/x-javascript,
application/javascript,application/json"/>
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps1"
unpackWARs="true" autoDeploy="true">
<Context path="/kbs-rule-srv" docBase="/app/project/kbs-rule-srv.war" reloadable="false" debug="0" />
</Host>
</Engine>
</Service>

<Service name="Catalina">
<Connector port="8702" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8445" maxThreads="500" acceptCount="500"
compression="on" URIEncoding="UTF-8"
compressionMinSize="2048"
maxPostSize="-1"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/plain,text/css,
text/javascript,text/json,application/x-javascript,
application/javascript,application/json"/>
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps2"
unpackWARs="true" autoDeploy="true">
<Context path="/kbs-rule-api" docBase="/app/project/kbs-rule-api.war" reloadable="false" debug="0" />
</Host>
</Engine>
</Service>

<Service name="Catalina">
<Connector port="8703" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8446" maxThreads="500" acceptCount="500"
compression="on" URIEncoding="UTF-8"
compressionMinSize="2048"
maxPostSize="-1"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/plain,text/css,
text/javascript,text/json,application/x-javascript,
application/javascript,application/json"/>
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps3"
unpackWARs="true" autoDeploy="true">
<Context path="/kbs-rule-web" docBase="/app/project/kbs-rule-web.war" reloadable="false" debug="0" />
</Host>
</Engine>
</Service>

<Service name="Catalina">
<Connector port="8704" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8447" maxThreads="500" acceptCount="500"
compression="on" URIEncoding="UTF-8"
compressionMinSize="2048"
maxPostSize="-1"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/plain,text/css,
text/javascript,text/json,application/x-javascript,
application/javascript,application/json"/>
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps4"
unpackWARs="true" autoDeploy="true">
<Context path="/kbs-xxl-job" docBase="/app/project/kbs-xxl-job.war" reloadable="false" debug="0" />
</Host>
</Engine>
</Service>

2、在tomcat文件根目录创建相应文件夹

3、将项目放置在相应文件夹下面

文章作者: 微光
文章链接: http://www.guduke.cn/2020/09/29/tomcat-deploy/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 微光
打赏
  • 微信
  • 支付宝

评论