环境:
CentOS 6.5 x64
JDK8
apache-tomcat-7.0.70
1、规划并配置端口:
TOMCAT | HTTP端口,默认8080 | AJP端口,默认8009 | 远程停服务端口,默认8005 |
原版apache-tomcat-7.0.70 | 71 <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/> | 93 <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> | 22 <Server port="8005" shutdown="SHUTDOWN"> |
tomcat7-com-80 | 71 <Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/> | 93 <Connector port="8030" protocol="AJP/1.3" redirectPort="8443" /> | 22 <Server port="8006" shutdown="SHUTDOWN"> |
tomcat7-ms-81 | 71 <Connector port="81" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/> | 93 <Connector port="8031" protocol="AJP/1.3" redirectPort="8443" /> | 22 <Server port="8007" shutdown="SHUTDOWN"> |
tomcat7-app-3800 | 71 <Connector port="3800" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/> | 93 <Connector port="8032" protocol="AJP/1.3" redirectPort="8443" /> | 22 <Server port="8008" shutdown="SHUTDOWN"> |
2、下载tomcat并解压,清空webapps下内容,新建ROOT目录,然后修改server.xml内容。
在大概126行下,添加应用的配置:
125 <Host name="localhost" appBase="webapps"
126 unpackWARs="true" autoDeploy="true">
<Context path="" docBase="ROOT" debug="0" reloadable="true" allowLinking="true"/>
这样的情况下,只需要将webapps目录下清空,新建一个ROOT文件夹,将应用复制到ROOT文件夹即可。
3、复制出三个tomcat服务器
cp -r apache-tomcat-7.0.70 tomcat7-com-80
cp -r apache-tomcat-7.0.70 tomcat7-ms-81
cp -r apache-tomcat-7.0.70 tomcat7-app-3800
4、按照规划配置三个tomcat的端口。
5、创建tomcat的环境设置脚本
在tomcat的bin目录下,建立setenv.sh文件:
#add tomcat pid CATALINA_PID="$CATALINA_BASE/tomcat-ms-81.pid" #add java opts JAVA_OPTS="-server -XX:PermSize=1024M -XX:MaxPermSize=1024M -Xss1024K -Xms512M -Xmx1024M -XX:MaxNewSize=512M" |
注意修改红色的PID名称,以上的参数含义如下:
-Xms JVM初始化堆内存大小
-Xmx JVM堆的最大内存
-Xss 线程栈大小
-XX:PermSize JVM非堆区初始内存分配大小
-XX:MaxPermSize JVM非堆区最大内存
6、部署应用,然后挨个启动tomcat,相关脚本如下:
/usr/local/hmg/tomcat7-com-80/bin/shutdown.sh /usr/local/hmg/tomcat7-ms-81/bin/shutdown.sh /usr/local/hmg/tomcat7-app-3800/bin/shutdown.sh /usr/local/hmg/tomcat7-com-80/bin/startup.sh /usr/local/hmg/tomcat7-ms-81/bin/startup.sh /usr/local/hmg/tomcat7-app-3800/bin/startup.sh