- 系统版本:Centos 5.3 64位系统
- Nginx版本为:httpd-2.2.13.tar.bz2
- Jdk版本为:1.6.0_18_64
- Tomcat版本为:Apache Tomcat/6.0.30
- 其他相似版本也可以!安装服务所需的包如下下载路径:本网站集成部分下载:
- jdk请到以下网站下载:请选择自己系统版本的jdk。
- https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewFilteredProducts-SingleVariationTypeFilter【Apache、Tomcat下载地址,下载到/usr/src下】
- cd /usr/src && wget http://blog.mgcrazy.com/download/{httpd-2.2.13.tar.bz2,apache-tomcat-6.0.30.tar.gz }
- cd /usr/src && tar -jxvf httpd-2.2.13.tar.bz2 && cd httpd-2.2.13/srclib/apr &&./configure --prefix=/usr/local/apr &&make &&make install &&cd ../apr-util/ && ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &&make&&make install && cd ../../ && ./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --with-mpm=worker --enable-deflate --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-proxy --enable-proxy-ajp --enable-proxy-balancer --enable-proxy-http --enable-rewrite --enable-charset-lite --disable-ipv6 --disable-dav --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
- mkdir -p /usr/java && mv jdk1.6.0_18 /usr/java/下
- vi /etc/profile 最后面加入以下语句:
- export JAVA_HOME=/usr/java/jdk1.6.0_18
- export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
- export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin
- source /etc/profile //使环境变量马上生效
- java –version //查看java版本
- cd /usr/src && tar xzf apache-tomcat-6.0.30.tar.gz
- 解压完成执行:
- mv apache-tomcat-6.0.30 /usr/local/tomcat_1 && cp /usr/local/tomcat_1 /usr/local/tomcat_2 -r
- cd /usr/local/tomcat_1/bin/ && vi setenv.sh 创建一个setenv.sh脚本文件,添加如下语句即可
- JAVA_HOME=/usr/java/jdk1.6.0_18
- JAVA_JRE=/usr/java/jdk1.6.0_18/jre
- 并且拷贝setenv.sh文件到tomcat_2/bin/下:
- cp -p /usr/local/tomcat_1/bin/setenv.sh /usr/local/tomcat_2/bin 下即可!
- 保存退出
- 检查两个tomcat下bin目录的*.sh 文件是否有可执行权限,如果没有则进入到相应的目录执行 chmod o+x *.sh 即可!
- 给两个tomcat分别创建不同的目录如下:mkdir -p /usr/webapps/{www_1,www_2}
- 分别在两个tomcat的conf下web.xml文件里面加入如下一行即可:
- 修改web应用里面WEB-INF目录下的web.xml文件,加入标签,也可以加在应用的web.xml里面如下:
- <distributable/>
- 直接加在</web-app>之前就可以了
- 这个是加入tomcat的session复制的,做tomcat集群必须需要这一步,否则用户的session就无法正常使用
- 配置完毕后,我们测试一下广播
- java -cp tomcat-replication.jar MCaster 224.0.0.1 45564 Terminal1
- java -cp tomcat-replication.jar MCaster 224.0.0.1 45564 Terminal2
- 信息: Initializing Coyote HTTP/1.1 on http-8080
- 2011-3-18 19:56:21 org.apache.catalina.startup.Catalina load
- 信息: Initialization processed in 1088 ms
- 2011-3-18 19:56:21 org.apache.catalina.core.StandardService start
- 信息: Starting service Catalina
- 2011-3-18 19:56:21 org.apache.catalina.core.StandardEngine start
- 信息: Starting Servlet Engine: Apache Tomcat/6.0.18
- 2011-3-18 19:56:21 org.apache.catalina.ha.tcp.SimpleTcpCluster start
- 信息: Cluster is about to start
- 2011-3-18 19:56:21 org.apache.catalina.tribes.transport.ReceiverBase bind
- 信息: Receiver Server Socket bound to:/192.168.2.79:4000
- 2011-3-18 19:56:21 org.apache.catalina.tribes.membership.McastServiceImpl setupSocket
- 信息: Setting cluster mcast soTimeout to 500
- 2011-3-18 19:56:21 org.apache.catalina.tribes.membership.McastServiceImpl waitForMembers
- 信息: Sleeping for 1000 milliseconds to establish cluster membership, start level:4
- 2011-3-18 19:56:22 org.apache.catalina.tribes.membership.McastServiceImpl waitForMembers
- 信息: Done sleeping, membership established, start level:4
- 2011-3-18 19:56:22 org.apache.catalina.tribes.membership.McastServiceImpl waitForMembers
- 信息: Sleeping for 1000 milliseconds to establish cluster membership, start level:8
- 2011-3-18 19:56:23 org.apache.catalina.tribes.membership.McastServiceImpl waitForMembers
- 信息: Done sleeping, membership established, start level:8
- 2011-3-18 19:56:23 org.apache.catalina.ha.deploy.FarmWarDeployer start
- 严重: FarmWarDeployer can only work as host cluster subelement!
- 2011-3-18 19:56:23 org.apache.catalina.ha.session.DeltaManager start
- 信息: Register manager to cluster element Engine with name Catalina
- 2011-3-18 19:56:23 org.apache.catalina.ha.session.DeltaManager start
- 信息: Starting clustering manager at
- 2011-3-18 19:56:23 org.apache.catalina.ha.session.DeltaManager getAllClusterSessions
- 信息: Manager [localhost#]: skipping state transfer. No members active in cluster group.
- 2011-3-18 19:56:23 org.apache.catalina.ha.session.JvmRouteBinderValve start
- 信息: JvmRouteBinderValve started
- 2011-3-18 19:56:23 org.apache.coyote.http11.Http11Protocol start
- 信息: Starting Coyote HTTP/1.1 on http-8080
- 2011-3-18 19:56:24 org.apache.jk.common.ChannelSocket init
- 信息: JK: ajp13 listening on /0.0.0.0:8411
- 2011-3-18 19:56:24 org.apache.jk.server.JkMain start
- 信息: Jk running ID=0 time=0/42 config=null
- 2011-3-18 19:56:24 org.apache.catalina.startup.Catalina start
- 信息: Server startup in 2676 ms
- 000,{-64, -88, 2, 79},4000, alive=86901,id={78 42 25 -19 -102 3 64 10 -76 93 69 -43 45 76 95 -112 }, payload={}, command={}, domain={}, ]. This operation will timeout if no session state has been received within 60 seconds.
- 2011-3-18 19:57:48 org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor report
- 信息: ThroughputInterceptor Report[
- Tx Msg:1 messages
- Sent:0.00 MB (total)
- Sent:0.00 MB (application)
- Time:0.01 seconds
- Tx Speed:0.04 MB/sec (total)
- TxSpeed:0.04 MB/sec (application)
- Error Msg:0
- Rx Msg:1 messages
- Rx Speed:0.00 MB/sec (since 1st msg)
- Received:0.00 MB]
- 2011-3-18 19:57:48 org.apache.catalina.ha.session.DeltaManager waitForSendAllSessions
- 信息: Manager [localhost#]; session state send at 11-3-18 下午7:57 received in 125 ms.
- 2011-3-18 19:57:48 org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor report
- 信息: ThroughputInterceptor Report[
- Tx Msg:2 messages
- Sent:0.00 MB (total)
- Sent:0.00 MB (application)
- Time:0.05 seconds
- Tx Speed:0.02 MB/sec (total)
- TxSpeed:0.02 MB/sec (application)
- Error Msg:0
- Rx Msg:2 messages
- Rx Speed:0.00 MB/sec (since 1st msg)
- Received:0.00 MB]
- 2011-3-18 19:57:49 org.apache.catalina.ha.session.JvmRouteBinderValve start
- 信息: JvmRouteBinderValve started
- 2011-3-18 19:57:49 org.apache.coyote.http11.Http11Protocol start
- 信息: Starting Coyote HTTP/1.1 on http-8081
- 2011-3-18 19:57:49 org.apache.jk.common.ChannelSocket init
- 信息: JK: ajp13 listening on /0.0.0.0:8412
- 2011-3-18 19:57:49 org.apache.jk.server.JkMain start
- 信息: Jk running ID=0 time=0/34 config=null
- 2011-3-18 19:57:49 org.apache.catalina.startup.Catalina start
- 信息: Server startup in 2962 ms
- Include conf/vhosts.conf
- Include conf/proxy.conf
- <VirtualHost *:80>
- ServerAdmin [email protected]
- DocumentRoot "/usr/webapps/www”
- ServerName 192.168.2.79
- <Directory "/usr/webapps/www ">
- AllowOverride None
- Options None
- Order allow,deny
- Allow from all
- </Directory>
- RewriteEngine On
- ProxyPreserveHost On
- RewriteRule ^$ balancer://wwwCluster/ [P,L,NC]
- RewriteRule ^/(.*)$ balancer://wwwCluster/$1 [P,L,NC]
- ProxyPass / balancer://wwwCluster/ stickysession=JSESSIONID|jsessionid nofailover=On
- ProxyPassReverse / balancer://wwwCluster/
- <Proxy balancer://wwwCluster>
- BalancerMember ajp://localhost:8411 loadfactor=1 route=tomcat1 smax=5 max=20 ttl=120 retry=300 timeout=15
- BalancerMember ajp://localhost:8412 loadfactor=1 route=tomcat2 smax=5 max=20 ttl=120 retry=300 timeout=15
- </Proxy>
- </VirtualHost>
- http://blog.mgcrazy.com/download/session-memcache/javolution-5.4.3.1.jar
- http://blog.mgcrazy.com/download/session-memcache/memcached-2.5.jar
- http://blog.mgcrazy.com/download/session-memcache/memcached-session-manager-1.3.0.jar
- http://blog.mgcrazy.com/download/session-memcache/msm-javolution-serializer-1.3.0.jar
- http://blog.mgcrazy.com/download/session-memcache/msm-javolution-serializer-cglib-1.3.0.jar
- http://blog.mgcrazy.com/download/session-memcache/msm-javolution-serializer-jodatime-1.3.0.jar
- 以上包请到新地址下载:
- http://chinaapp.sinaapp.com//download/memcached-session/memcached-session-manager.tar.gz
- 解压即可!
- <Manager className=”de.javakaffee.web.msm.MemcachedBackupSessionManager”
- memcachedNodes=”n1:192.168.0.84:11211″
- requestUriIgnorePattern=”.*\.(png|gif|jpg|css|js)$”
- sessionBackupAsync=”false”
- sessionBackupTimeout=”100″
- transcoderFactoryClass=”de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory”
- copyCollectionsForSerialization=”false” />
- <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
- <%
- %>
- http://blog.mgcrazy.com
- <%out.print(request.getSession()) ;%>
- <%out.println(request.getHeader("Cookie")); %>
所以配置完毕,重启tomcat和apache即可!
- <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
- <%
- %>
- http://wgkgood.gicp.net
- <%out.print(request.getSession()) ;%>
- <%out.println(request.getHeader("Cookie")); %>
- http://wgkgood.gicp.net
- org.apache.catalina.session.StandardSessionFacade@2d7aece8
- JSESSIONID=FEB19E24719ED666D1C9C50A7A09A2BA.tomcat2
- 另一个firefox浏览器窗口为:
- http://blog.mgcrazy.com
- org.apache.catalina.session.StandardSessionFacade@259e215b
- rtime=0; ltime=1298014951125; cnzz_eid=85744900-1298010049-; Hm_lvt_0e74098a87be059a433e5a74f1b5fecf=1298014951312; Hm_lvt_b7c035fd79b2c378053e06c86493de76=1300439158373; JSESSIONID=B2574ABB491F50F37162479BD3FE761C.tomcat1
http://blog.mgcrazy.com/thread-976-1.html
http://bbs.linuxtone.org/thread-1195-1-1.html