Tomcat---多实例
多实例
作用:
多实例运行不同的应用(类似虚拟主机)
多实例运行相同的应用(实现负载均衡,支持高并发处理,session问题)
tomcat单机多实例配置
Tomcat:/usr/local/tomcat/{bin,lib}
instans1: /usr/local/tomcat/instans1/{conf,logs,temp,work,webapps} 8081
instans2: /usr/local/tomcat/instans2/{conf,logs,temp,work,webapps} 8082
instans3: /usr/local/tomcat/instans3/{conf,logs,temp,work,webapps} 8083
webapps: /webapps/ROOT
1. Tomcat安装<略>
2. 配置多实例目录
# tree -d -L 3 /usr/local/tomcat/
/usr/local/tomcat/
├── bin
├── lib
├── instance1
│ ├── conf
│ ├── logs
│ ├── temp
│ ├── webapps
│ └── work
├├── instance2
│ ├── conf
│ ├── logs
│ ├── temp
│ ├── webapps
│ └── work
├── instance3
├── conf
├── logs
├── temp
├── webapps
└── work
3. 配置实例server.xml
# vim /usr/local/tomcat/instance1/conf/server.xml
# vim /usr/local/tomcat/instance1/conf/server.xml <!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> --> <Server port="8091" shutdown="SHUTDOWN"> <Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Host name="localhost" appBase="/webapps" unpackWARs="true" autoDeploy="true">
4. 写启动脚本
# vim /usr/local/tomcat/instance1/tomcat-instance1.sh
#!/bin/bash
#instance1
export CATALINA_HOME="/usr/local/tomcat"
export CATALINA_BASE="/usr/local/tomcat/instance1"
case "$1" in
start)
$CATALINA_HOME/bin/startup.sh;;
stop)
$CATALINA_HOME/bin/shutdown.sh;;
restart)
$CATALINA_HOME/bin/shutdown.sh
sleep 3
$CATALINA_HOME/bin/startup.sh;;
esac
5. 启动测试
# /usr/local/tomcat/instans1/tomcat-instance1.sh start
# /usr/local/tomcat/instans2/tomcat-instance2.sh start
# /usr/local/tomcat/instans2/tomcat-instance3.sh start
# netstat -tanp |grep 80
tcp 0 0 :::8081 :::* LISTEN 1587/java
tcp 0 0 :::8082 :::* LISTEN 1560/java
tcp 0 0 :::8083 :::* LISTEN 1752/java
tcp 0 0 ::ffff:127.0.0.1:8091 :::* LISTEN 1587/java
tcp 0 0 ::ffff:127.0.0.1:8092 :::* LISTEN 1560/java
tcp 0 0 ::ffff:127.0.0.1:8093 :::* LISTEN 1752/java
tcp 0 0 :::8009 :::* LISTEN 1560/java
思考将三个启动脚本合一???
/bin/startup.sh 脚本