随笔-153  评论-235  文章-19  trackbacks-0
参照:  http://www.360doc.com/showWeb/0/0/207707.aspx

环境:
Tomcat 5.5.20
Apache 2.2.3


1.机器A 里有TomcatA\webapps\Test目录, 机器B里TomcatB\webapps\Test目录。其web.xml文件一样,两个都在</web-app>之前加上<distributable/>

2.两个Tomcat\conf\server.xml的如下内容去掉注释,没有就在</Host>之前加上去:


<Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
                 managerClassName
="org.apache.catalina.cluster.session.DeltaManager"
                 expireSessionsOnShutdown
="false"
                 useDirtyFlag
="true"
                 notifyListenersOnReplication
="true">

            
<Membership 
                
className="org.apache.catalina.cluster.mcast.McastService"
                mcastAddr
="228.0.0.4"
                mcastPort
="45564"
                mcastFrequency
="500"
                mcastDropTime
="3000"/>

            
<Receiver 
                
className="org.apache.catalina.cluster.tcp.ReplicationListener"
                tcpListenAddress
="auto"
                tcpListenPort
="4001"
                tcpSelectorTimeout
="100"
                tcpThreadCount
="6"/>

            
<Sender
                
className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
                replicationMode
="pooled"
                ackTimeout
="15000"
                waitForAck
="true"/>

            
<Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
                   filter
=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>
                   
            
<Deployer className="org.apache.catalina.cluster.deploy.FarmWarDeployer"
                      tempDir
="/tmp/war-temp/"
                      deployDir
="/tmp/war-deploy/"
                      watchDir
="/tmp/war-listen/"
                      watchEnabled
="false"/>
                      
            
<ClusterListener className="org.apache.catalina.cluster.session.ClusterSessionListener"/>
        
</Cluster>


3.接下来配置Apache\conf\httpd.conf
其中这三个去掉注释:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so


末尾加上:
ProxyRequests Off

ProxyPass /helloworld balancer://mycluster stickysession
=jsessionid nofailover=On

<Proxy balancer://mycluster>
BalancerMember http://
192.168.0.100:8080
BalancerMember http://
192.168.0.101:8080
</Proxy>

<Location /balancer-manager>
SetHandler balancer-manager
Order Deny
,Allow
Deny from all
Allow from all
</Location>

<Location /server-status>
SetHandler server-status
Order Deny
,Allow
Deny from all
Allow from all
</Location>


说明:
ProxyPass /helloworld balancer://mycluster stickysession=jsessionid nofailover=On
<Proxy balancer://mycluster>
BalancerMember http://192.168.0.100:8080
BalancerMember http://192.168.0.101:8080
</Proxy>
ProxyPass为代理转发的Url,即将所有访问/helloworld的请求转发到群集balancer://mycluster
BalancerMember为群集的成员,即群集服务器AB,负载均衡服务器会根据均衡规则来将请求转发给BalancerMember


4.测试页面,
TomcatA\webapps\Test\index.html内容如下:
<html>
<head><title>Tomcat 5.5.20 群集1</title></head>

<body>
<center>Tomcat 1号机
</center>
</body>
</html>


TomcatB\webapps\Test\index.html内容如下:
<html>
<head><title>Tomcat 5.5.20 群集2</title></head>

<body>
<center>Tomcat 2号机在TomcatB机上
</center>
</body>
</html>


启动TomcatA和TomcatB,再启动Apache
http://localhost/helloworld/Test/index.html
后有出现上面两个页面的任一个说明配置成功。
不断刷新,这个页面不断交替。

:)
posted on 2007-03-15 16:59 流浪汗 阅读(1475) 评论(0)  编辑  收藏 所属分类: Tomcat

只有注册用户登录后才能发表评论。


网站导航: