日期:2014-05-16  浏览次数:21012 次

(转)Apache2 + Tomcat6配置负载均衡
 
1. 安装Apache和Tomcat,这里假定Apache2.2.3,Tomcat6.x;且Apache安装在apachehost,tomcat分别安装在tomcathost1和tomcathost2上;
2. 修改/etc/hosts文件,确定以下行没有被注释掉
view plaincopy to clipboardprint?
LoadModule proxy_module modules/mod_proxy.so  
LoadModule proxy_http_module modules/mod_proxy_http.so  
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so 
  LoadModule proxy_module modules/mod_proxy.so
  LoadModule proxy_http_module modules/mod_proxy_http.so
  LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
3. 修改/etc/hosts文件,添加以下行:
view plaincopy to clipboardprint?
ProxyRequests off  
<Proxy balancer://tccluster> 
    BalancerMember http://tomcathost1:8080 loadfactor=2 max=150 smax=145 
    BalancerMember http://tomcathost2:8080 loadfactor=1 max=150 smax=145 
    Order Deny,Allow  
    Allow from all  
</Proxy> 
<Location /balancer-manager> 
    SetHandler balancer-manager  
    Order Deny,Allow  
    Allow from all  
</Location> 
<Location /examples> 
    ProxyPass balancer://tccluster/examples stickysession=jsessionid 
    ProxyPassReverse balancer://tccluster/examples  
    Order Deny,Allow  
    Allow from all  
</Location> 
  ProxyRequests off
  <Proxy balancer://tccluster>
      BalancerMember http://tomcathost1:8080 loadfactor=2 max=150 smax=145
      BalancerMember http://tomcathost2:8080 loadfactor=1 max=150 smax=145
      Order Deny,Allow
      Allow from all
  </Proxy>
  <Location /balancer-manager>
      SetHandler balancer-manager
      Order Deny,Allow
      Allow from all
  </Location>
  <Location /examples>
      ProxyPass balancer://tccluster/examples stickysession=jsessionid
      ProxyPassReverse balancer://tccluster/examples
      Order Deny,Allow
      Allow from all
  </Location>
4. 确定apachehost和两台tomcathost可以互访,并且两个tomcat机器在一个网段内;
5. 确定两台tomcat host多播已经打开,在Linux机器上可以使用cat /proc/net/dev_mcast检查,如果文件存在基本上就是打开了;另外确定两台tomcat机器的/etc/hosts文件中包含“xxx.xxx.xxx.xxx    hostname”比如“172.17.1.101    tomcathost1”或“172.17.1.102    tomcathost2”;
6. 修改两个tomcat的conf/server.xml文件,对Engine节点分别添加jvmRoute="tomcat1"和jvmRoute="tomcat2",并添加以下内容:
view plaincopy to clipboardprint?
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"   
    channelSendOptions="6"> 
      
      
    <Manager className="org.apache.catalina.ha.session.DeltaManager" 
        expireSessionsOnShutdown="false" 
        notifyListenersOnReplication="true"/> 
    <!--  
    <Manager className="org.apache.catalina.ha.session.BackupManager" 
        expireSessionsOnShutdown="false" 
        notifyListenersOnReplication=