Tomcat--多实例

配置信息

 centos:7.8

 tomcat:7.0.3

 instans1:/usr/local/tomcat/instans1 8081

 instans2:/usr/local/tomcat/instans1 8082

 instans3:/usr/local/tomcat/instans1 8083

 webapps:/webapps/ROOT

 

1 多实例作用

 多实例运行不同的应用  类似于虚拟主机

 多实例运行相同的应用  实现负载均衡 支持高并发处理 session问题

 

2 配置

#创建实例目录
mkdir /usr/local/tomcat/instans{1,2,3}

#拷贝文件
cp -r /usr/local/tomcat/{conf,logs,temp,work,webapps} /usr/local/tomcat/instans1

#拷贝目录
cp -r /usr/local/tomcat/instans1/* /usr/local/tomcat/instans2
cp -r /usr/local/tomcat/instans1/* /usr/local/tomcat/instans3

 

3 修改配置文件

[root@localhost ~]# vim /usr/local/tomcat/instans1/conf/server.xml
<Server port="8005" shutdown="SHUTDOWN">        #各实例不同端口
    <Connector port="8081" protocol="HTTP/1.1"     #各实例不同端口
    <Host name="localhost"  appBase="/webapps"     #改为实例的发布目录

 

4 编写启停脚本

[root@localhost ~]# cat /usr/local/tomcat/instans1/tomcat-instans1.sh 
#!/bin/bash
#instans1
export CATALINA_HOME="/usr/local/tomcat"
export CATALINA_BASE="/usr/local/tomcat/instans1"
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
[root@localhost ~]# chmod +x /usr/local/tomcat/instans1/tomcat-instans1.sh

 

5 启动服务

/usr/local/tomcat/instans1/tomcat-instans1.sh start
/usr/local/tomcat/instans2/tomcat-instans2.sh start
/usr/local/tomcat/instans3/tomcat-instans3.sh start

posted @ 2020-12-03 22:14  心恩惠动  阅读(136)  评论(0编辑  收藏  举报