Tomcat高负载WEB服务器Tomcat多实例

【Tomcat高负载WEB服务器Tomcat多实例】关山初度尘未洗,策马扬鞭再奋蹄!这篇文章主要讲述Tomcat高负载WEB服务器Tomcat多实例相关的知识,希望能为你提供帮助。
关闭主站

bash /usr/local/tomcat/bin/shutdown.sh

准备多实例主目录
mkdir/usr/local/tomcat/instance1..3

制作实例工作目录
# cp -r /usr/local/tomcat/conf,logs,temp,work /usr/local/tomcat/instance1/
# cp -r /usr/local/tomcat/conf,logs,temp,work /usr/local/tomcat/instance2/
# cp -r /usr/local/tomcat/conf,logs,temp,work /usr/local/tomcat/instance3/

查看目录结构
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

修改端口
将web配置文件拷贝三份。分别修改为不同端口
vim /usr/local/tomcat/instance1/conf/server.xml

服务端口 8080 替换成 8081
< Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

程序工作端口:8005替换成 8091
< Server port="8091" shutdown="SHUTDOWN">

网站目录:webapps 替换成 另一个目录
appBase="/webapps"

vim /usr/local/tomcat/instance2/conf/server.xml

服务端口 8080 替换成 8082
< Connector port="8082" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

程序工作端口:8005替换成 8092
< Server port="8092" shutdown="SHUTDOWN">

网站目录:webapps 替换成 另一个目录
appBase="/webapps"

vim /usr/local/tomcat/instance2/conf/server.xml

服务端口 8080 替换成 8083
< Connector port="8083" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

程序工作端口:8005替换成 8093
< Server port="8093" shutdown="SHUTDOWN">

网站目录:webapps 替换成 另一个目录
appBase="/webapps"

启动脚本
vim /usr/local/tomcat/instance1/ins1.sh

#!/bin/bash
#instance1
. /etc/init.d/functions
#functions系统自带脚本。功能函数
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 5
$CATALINA_HOME/bin/startup.sh
; ;
esac
export java_OPTS=-Xms64m -Xmx128m

vim /usr/local/tomcat/instance1/ins2.sh

#!/bin/bash
#instance2
. /etc/init.d/functions
#functions系统自带脚本。功能函数
export CATALINA_BASE="/usr/local/tomcat/instance2"

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

vim /usr/local/tomcat/instance1/ins3.sh

#!/bin/bash
#instance3
. /etc/init.d/functions
#functions系统自带脚本。功能函数
export CATALINA_BASE="/usr/local/tomcat/instance3"

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

赋权
chmod +x /usr/local/tomcat/instance1/ins1.sh
chmod +x /usr/local/tomcat/instance2/ins2.sh
chmod +x /usr/local/tomcat/instance3/ins3.sh

网站源码
mkdir /webapps
cp -r /usr/local/tomcat/webapps/ROOT/ /webapps/

启动
/usr/local/tomcat/instance1/ins1.sh star
/usr/local/tomcat/instance2/ins2.sh start
/usr/local/tomcat/instance3/ins3.sh start

测试
http://192.168.0.104:8091
http://192.168.0.104:8092
http://192.168.0.104:8093


    推荐阅读