Web服务器群集——TOMCAT单机多实例配置
Posted Pakho`
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Web服务器群集——TOMCAT单机多实例配置相关的知识,希望对你有一定的参考价值。
TOMCAT单机多实例配置
前言
关闭TOMCAT主站
[root@tomcat ~]# bash /usr/local/tomcat/bin/shutdown.sh #关闭TOMCAT
一、 关于TOMCAT
1.1 TOMCAT主目录
[root@tomcat ~]# ls /usr/local/tomcat/
[root@tomcat tomcat]# tree -L 1
.
├── bin #存放tomcat管理脚本
├── conf #tomcat配置文件存放目录
├── lib #web应用调用的jar包存放路径
├── LICENSE #授权
├── logs #tomcat日志存放目录,catalina.out为主要输出日志
├── NOTICE
├── RELEASE-NOTES
├── RUNNING.txt
├── temp #存放临时目录
├── webapps #web程序存放目录
└── work #存放编译产生的.java 与 .class文件
1.2 Webapps目录
[root@tomcat webapps]# tree -L 1
.
├── docs #tomcat帮助文档
├── examples #wenb应用示例
├── host-manager #主机管理
├── manager #管理
└── ROOT #默认站点根目录
1.3 默认网站主目录(主页)
/usr/local/tomcat/webapps/ROOT
1.4 Tomcat配置文件目录(conf)
[root@tomcat tomcat]# tree -L 1 conf/
conf/
├── Catalina
├── catalina.policy
├── catalina.properties
├── context.xml
├── logging.properties
├── server.xml #tomcat主配置文件
├── tomcat-users.xml #tomcat管理用户配置文件
└── web.xml
1.5 Tomcat日志
[root@tomcat tomcat]# tailf /usr/local/tomcat/logs/catalina.out
二、准备多实例主目录
[root@tomcat ~]# mkdir /usr/local/tomcat/instance{1..3}
三、制作实例工作目录
一些配置文件
[root@tomcat ~]# cp -r /usr/local/tomcat/{conf,logs,temp,work} /usr/local/tomcat/instance1/
[root@tomcat ~]# cp -r /usr/local/tomcat/{conf,logs,temp,work} /usr/local/tomcat/instance2/
[root@tomcat ~]# cp -r /usr/local/tomcat/{conf,logs,temp,work} /usr/local/tomcat/instance3/
四、修改端口
实例一
[root@tomcat tomcat]# vim /usr/local/tomcat/instance1/conf/server.xml
<!-- 修改前 -->
<Connector port="8080" protocol="HTTP/1.1" #服务端口
connectionTimeout="20000"
redirectPort="8443" />
<!-- 修改后 -->
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000" #连接超时2w毫秒
redirectPort="8443" /> #端口重定向
<!-- 修改前 -->
<Server port="8005" shutdown="SHUTDOWN"> #程序工作端口
<!-- 修改后 -->
<Server port="8091" shutdown="SHUTDOWN">
<!-- 修改前 -->
<Host name="localhost" appBase="webapps" #网站目录
<!-- 修改后 -->
<Host name="localhost" appBase="/webapps"
[root@tomcat ~]# mkdir /webapps
[root@tomcat ~]# cp /usr/local/tomcat/instance1/conf/server.xml /usr/local/tomcat/instance2/conf/ #覆盖
[root@tomcat ~]# cp /usr/local/tomcat/instance1/conf/server.xml /usr/local/tomcat/instance3/conf/ #覆盖
实例二
[root@tomcat ~]# vim /usr/local/tomcat/instance2/conf/server.xml
<Connector port="8082" protocol="HTTP/1.1" #8082
connectionTimeout="20000"
redirectPort="8443" />
<Server port="8092" shutdown="SHUTDOWN"> #8092
#本实验网站根目录就设置了一次,对于生产环境应存放于不同路径
实例三
[root@tomcat ~]# vim /usr/local/tomcat/instance3/conf/server.xml
<Connector port="8083" protocol="HTTP/1.1" #8083
connectionTimeout="20000"
redirectPort="8443" />
<Server port="8093" shutdown="SHUTDOWN"> #8093
五、配置启动脚本
实例一
[root@tomcat ~]# vim /usr/local/tomcat/instance1/ins1.sh
#!/bin/bash
#instance1
. /etc/init.d/function
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' #优化时所需要的JAVA内存大小
[root@tomcat ~]# cp /usr/local/tomcat/instance1/ins1.sh /usr/local/tomcat/instance2/ins2.sh
[root@tomcat ~]# cp /usr/local/tomcat/instance1/ins1.sh /usr/local/tomcat/instance3/ins3.sh
实例二
#!/bin/bash
#instance1
. /etc/init.d/function
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'
实例三
#!/bin/bash
#instance1
. /etc/init.d/function
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'
六、对启动脚本进行授权
[root@tomcat ~]# chmod +x /usr/local/tomcat/instance1/ins1.sh
[root@tomcat ~]# chmod +x /usr/local/tomcat/instance2/ins2.sh
[root@tomcat ~]# chmod +x /usr/local/tomcat/instance3/ins3.sh
七、准备网站源码
[root@tomcat ~]# cp -r /usr/local/tomcat/webapps/ROOT/ /webapps/ #源码为jspgou的源码
八、启动TOMCAT服务器
[root@tomcat ~]# /usr/local/tomcat/instance1/ins1.sh start
[root@tomcat ~]# /usr/local/tomcat/instance2/ins2.sh start
[root@tomcat ~]# /usr/local/tomcat/instance3/ins3.sh start
[root@tomcat ~]# netstat -anpt | grep java #观察8081 8082 8083端口
tcp6 0 0 :::8009 :::* LISTEN 16700/java
tcp6 0 0 :::8081 :::* LISTEN 16700/java
tcp6 0 0 :::8082 :::* LISTEN 17309/java
tcp6 0 0 :::8083 :::* LISTEN 17231/java
...
九、浏览网页验证
http://192.168.100.10:8081/
http://192.168.100.10:8082/
http://192.168.100.10:8083
实验完成!
以上是关于Web服务器群集——TOMCAT单机多实例配置的主要内容,如果未能解决你的问题,请参考以下文章