webapps:
拷贝原来单实例的webapps到/下
/webapps/ROOT
1. 以单实例为基础
[root@www ~]# /usr/local/tomcat/bin/shutdown.sh
2. 配置多实例目录
分别创建目录instance1 instance2 instance3,拷贝原来的conf,log,temp,work到3个目录下
[root@www ~]# tree -d -L 2 /usr/local/tomcat/
/usr/local/tomcat/
├── bin
├── instance1
│ ├── conf
│ ├── logs
│ ├── temp
│ └── work
├── instance2
│ ├── conf
│ ├── logs
│ ├── temp
│ └── work
├── instance3
│ ├── conf
│ ├── logs
│ ├── temp
│ └── work
└── lib
3. 配置实例server.xml
[root@www ~]# vim /usr/local/tomcat/instance1/conf/server.xml
<!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> -->
<Server port=" 8091" shutdown="SHUTDOWN"> //修改8005
<Connector port=" 8081" protocol="HTTP/1.1" //删掉8080和8009的配置,添加此配置
connectionTimeout="20000"
redirectPort="8443" />
<Host name="localhost" appBase=" /webapps" //修改网站基准目录
unpackWARs="true" autoDeploy="true">
......
4. 脚本内容
[root@www ~]# vim /usr/local/tomcat/instance1/ins1.sh
case "$1" in
start)
$CATALINA_HOME/bin/startup.sh;;
stop)
$CATALINA_HOME/bin/shutdown.sh;;
restart)
$CATALINA_HOME/bin/shutdown.sh
sleep 5
$CATALINA_HOME/bin/startup.sh;;
esac
export JAVA_OPTS='-Xms64m -Xmx128m'
5. 启动测试
[root@www ~]# /usr/local/tomcat/instance1/ins1.sh start
[root@www ~]# /usr/local/tomcat/instance2/ins2.sh start
[root@www ~]# /usr/local/tomcat/instance3/ins3.sh start
[root@www ~]# ss -tnlp |grep :80 |column -t
LISTEN 0 100 :::8081 :::* users:(("java",pid=7288,fd=48))
LISTEN 0 100 :::8082 :::* users:(("java",pid=7468,fd=48))
LISTEN 0 100 :::8083 :::* users:(("java",pid=7496,fd=48))
LISTEN 0 1 ::ffff:127.0.0.1:8091 :::* users:(("java",pid=7288,fd=61))
LISTEN 0 1 ::ffff:127.0.0.1:8092 :::* users:(("java",pid=7468,fd=61))
LISTEN 0 1 ::ffff:127.0.0.1:8093 :::* users:(("java",pid=7496,fd=61))
<Server port=" 8091" 管理实例端口
<Connector port=" 8081" protocol="HTTP/1.1 提供web服务端口
<Connector port="8009" protocol="AJP/1.3" 用于前端如Apache通过AJP方式连接tomcat的端口
webapps:
拷贝原来单实例的webapps到/下
/webapps/ROOT
Tomcat 一机多实例
多实例运行不同的应用(类似虚拟主机)
多实例运行相同的应用(实现负载均衡,支持高并发处理,session问题)
tomcat单机多实例配置
CATALINA_BASE:
instance1: /usr/local/tomcat/instance1/{conf,logs,temp,work} 8081 8091
instance2: /usr/local/tomcat/instance2/{conf,logs,temp,work} 8082 8092
instance3: /usr/local/tomcat/instance3/{conf,logs,temp,work} 8083 8093#!/bin/bash
#instance1
. /etc/init.d/functions
export CATALINA_BASE="/usr/local/tomcat/instance1"