最近公司项目由于开发人员没有sessions共享的概念,所以准备使用tomcat集群来完成session的共享。
首先,测试环境如下:
|-tomcat01 :8081 shutdown 8015
Nginx -|-tomcat02 :8082 shutdown 8025
|_tomcat03 :8083 shutdown 8035
1,详细部署
1,1JDK安装
./jdk-6u25-linux-x64-rpm.bin
vim /etc/profile
添加如下配置,由于打算在同一台服务器上安装多个tomcat,如下配置:
JAVA_HOME=/usr/java/jdk1.6.0_25
CLASS_PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib
PATH=$PATH:$JAVA_HOME/bin:.
export JAVA_HOME
1,2安装tomcat
tar -zxvf apache-tomcat-7.0.20.tar.gz
mv apache-tomcat-7.0.20 tomcat01
cd /usr/tomcat01/conf/
vim /usr/tomcat01/conf/server.xml#分别更改tomcat目录下server.xml的配置,端口按照之前设置的。
tomcat01
tomcat02
tomcat03
1,3配置tomcat启动变量 同理tomcat01 tomcat02 tomcat03
vim /usr/tomcat01/bin/startup.sh
添加如下定义
JAVA_HOME=/usr/java/jdk1.6.0_25
CATALINA_HOME=/usr/tomcat01
export CATALINA_HOME
1,4配置集群
vim /usr/tomcat01/conf/server.xml
+++++++++++++++++++++++++++++++++++++++++++
-
channelSendOptions="8">
-
-
-
expireSessionsOnShutdown="false"
-
notifyListenersOnReplication="true"/>
-
-
#tomcat集群IO层配置
-
-
address="228.0.0.4" #组播地址
-
port="45564"
-
frequency="500"
-
dropTime="3000"/>
-
-
address="auto"
-
port="4000"
-
autoBind="100"
-
selectorTimeout="5000"
-
maxThreads="6"/>
-
-
-
-
-
-
-
-
-
-
filter=""/>
-
-
-
-
tempDir="/tmp/war-temp/"
-
deployDir="/tmp/war-deploy/"
-
watchDir="/tmp/war-listen/"
-
watchEnabled="false"/>
-
-
-
-
按照如上的配置,分别配置tomcat01 02 03
然后在
vim /usr/tomcat01/webapps/ROOT/WEB-INF/web.xml
添加该配置
2,配置Nginx(略)
- upstream bakend {
-
server 127.0.0.1:8081 weight=10;
-
server 127.0.0.1:8082 weight=10;
-
server 127.0.0.1:8083 weight=10;
-
}
3,分别在tomcat的webapps目录下放如下测试脚本:
4,启动nginx和tomcat集群
然后在浏览器输入
在name和Value输入
提交页面发现seession只会在各个tomcat直接复制,且输入的值不变
5,查看主机日志会有如下:
- Sep 28, 2011 4:30:48 PM org.apache.catalina.ha.tcp.SimpleTcpCluster memberAdded
-
INFO: Replication member added:org.apache.catalina.tribes.membership.MemberImpl[tcp://{127, 0, 0, 1}:4002,{127, 0, 0, 1},4002, alive=58252, securePort=-1, UDP Port=-1, id={-103 -97 33 33 -4 -105 77 -113 -110 108 -31 122 67 -90 -22 123 }, payload={}, command={}, domain={}, ]
-
Sep 28, 2011 4:30:48 PM org.apache.catalina.ha.tcp.SimpleTcpCluster memberAdded
-
INFO: Replication member added:org.apache.catalina.tribes.membership.MemberImpl[tcp://{127, 0, 0, 1}:4001,{127, 0, 0, 1},4001, alive=79844, securePort=-1, UDP Port=-1, id={-29 -73 109 76 57 4 64 -50 -69 32 -7 -44 78 90 -115 -60 }, payload={}, command={}, domain={}, ]
-
Sep 28, 2011 4:30:48 PM org.apache.catalina.tribes.io.BufferPool getBufferPool
-
INFO: Created a buffer pool with max size:104857600 bytes of type:org.apache.catalina.tribes.io.BufferPool15Impl
通过监听端口可以发现,session正常进行复制了。
阅读(2134) | 评论(0) | 转发(0) |