天天看点

实现在tomcat中跑多个服务器实例

server.xml 注释

  server:

  server只能有一个,它代表整个jvm,server可以包含一个或者多个service

  service:

  conector:

  connector用来为container接收请求,和返回响应的。

  engine:

  engine是顶层container,它可以包含一个或者多个host

  host:

  host是虚拟主机,它可以包含一个或者多个context

  context:

  context对应一个web application。

  最近抽时间研究了一下tomcat的源码,发现可以增加多个service到server.xml中,实现在tomcat中跑多个服务器 实例,在server.xml中增加如下配置信息:

  xml代码

  <service name="catalina2">

  <connector port="8081"

  maxthreads="150" minsparethreads="25" maxsparethreads="75"

  enablelookups="false" redirectport="8443" acceptcount="100"

  debug="0" connectiontimeout="20000"

  disableuploadtimeout="true" />

  <connector port="8010"

  enablelookups="false" redirectport="8443" debug="0"

  protocol="ajp/1.3" />

  <engine name="catalina" defaulthost="localhost" debug="0">

  <logger classname="org.apache.catalina.logger.filelogger"

  prefix="catalina2_log." suffix=".txt"

  timestamp="true"/>

  <realm classname="org.apache.catalina.realm.userdatabaserealm"

  debug="0" resourcename="userdatabase"/>

  <host name="localhost" debug="0" appbase="webapps2"

  unpackwars="true" autodeploy="true"

  xmlvalidation="false" xmlnamespaceaware="false">

  directory="logs"   prefix="localhost2_log." suffix=".txt"

  </host>

  </engine>

  </service>