Windows7 下Tomcat多实例部署

0. 说明

将多个Java EE项目部署到一个Tomcat下可能会造成许多不良后果,比如

  • 多个项目不容易排查问题,尤其是调试的时候
  • 一旦一个项目需要重启Tomcat,其他项目也会受影响

可以用部署Tomcat多个实例的方法来解决上述问题。
本文只介绍在Windows7系统下Tomcat7多实例部署的步骤,参考来自Tomcat根目录下的RUNNING文件。

1. Multiple Instances Summary

Tomcat supports installation of multiple instances. You can have a single installation of Tomcat with multiple instances running on different IP/port combinations, or multiple Tomcat versions, each running one or more instances on different IP/ports.

2. Each instance folder will need the following structure:

  • conf
  • logs
  • temp
  • webapps
  • work

At a minimum, conf should contain a copy of the following files from CATALINA_HOME\conf. Any files not copied and edited, will be picked up by default from CATALINA_HOME\conf, i.e. CATALINA_BASE\conf files override defaults from CATALINA_HOME\conf.

  • server.xml
  • web.xml

3. Modify the configuration of each instance

You must edit CATALINA_BASE\conf\server.xml to specify a unique IP/port for the instance to listen on. Find the line that contains <Connector port="8080" ... and add an address attribute and/or update the port number so as to specify a unique IP/port combination.

4. Install first instance

To install an instance, first set the CATALINA_HOME environment variable to the name of the Tomcat installation directory. Then create a second environment variable CATALINA_BASE and point this to the instance folder. Then run service.bat install command specifying a service name.

set "CATALINA_HOME=c:\tomcat_7"
set "CATALINA_BASE=c:\tomcat_7\instances\instance1"
service.bat install instance1

To modify the service settings, you can run tomcat7w //ES//instance1-service.

5. Add an instance

For additional instances, create additional instance folder, update the CATALINA_BASE environment variable, and run the service install again.

set CATALINA_BASE=c:\tomcat_7\instances\instance2
service install instance2

6. Write the commands above in a bat file can be

@echo off

set "CATALINA_HOME=c:\tomcat_7"
set "SERVICE_INSTALLER=%CATALINA_HOME\bin\service.bat"

rem instance1
set "CATALINA_BASE=c:\tomcat_7\instances\instance1"
call "SERVICE_INSTALLER" install instance1-service

rem instance2
set "CATALINA_BASE=c:\tomcat_7\instances\instance2"
rem java configuration because of memeory leak
set "JAVA_OPTS=-Xms1024m -Xmx2000m"
call "SERVICE_INSTALLER" install instance2-service

rem instance3
set "CATALINA_BASE=c:\tomcat_7\instances\instance3"
call "SERVICE_INSTALLER" install instance3-service

7. 查看各个实例的日志,看是否都启动成功!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值