Apache2,2和tomcat6配置集群

1. 环境说明

apache_2.2.14-win32-x86-no_ssl.msi

tomcat6.0

下载mod_jk-1.2.28-httpd-2.2.3.so
http://apache.justdn.org/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/mod_jk-1.2.28-httpd-2.2.3.somod_jk-1.2.28-httpd-2.2.3.so

2.负载均衡的配置

  (1) 在httpd.conf最后添加一行: Include conf/mod_jk.conf

  (2).mod_jk.conf 的内容   mod_jk.conf放在apache/conf目录下

      #加载mod_jk Module

      LoadModule jk_module modules/mod_jk-1.2.28-httpd-2.2.3.so

      #指定 workers.properties文件路径
      JkWorkersFile conf/workers.properties

      #指定那些请求交给tomcat处理
      JkMount /*.jsp controller

  (3)workers.properties 内容,workers.properties也放在apache/conf目录下

     worker.list = controller,tomcat1,tomcat2

     worker.tomcat1.port=8009        
     worker.tomcat1.host=localhost    #tomcat的主机地址,如不为本机,请填写ip地址
     worker.tomcat1.type=ajp13
     worker.tomcat1.lbfactor = 1        #server的加权比重,值越高,分得的请求越多
 

     worker.tomcat2.port=9009     
     worker.tomcat2.host=localhost
     worker.tomcat2.type=ajp13
     worker.tomcat2.lbfactor = 1

   

      #========controller,负载均衡控制器========

     worker.controller.type=lb
     worker.controller.balanced_workers=tomcat1,tomcat2     #指定分担请求的tomcat
     #worker.controller.sticky_session=1
     worker.controller.sticky_session=false

 

3.编写一个test.jsp的测试程序

  <%
   System.out.println("===========================");
  %>
  把test放到tomcat1,tomcat2的webapps下
  启动tomcat1,tomcat2进行测试
 
   通过 http://localhost/test/test.jsp 访问,查看tomcat1的窗口,可以看到打印了一行"=========="
   再刷新一次,tomcat2也打印了一条,再刷新,可以看到请求会被tomcat1,tomcat2轮流处理,实现了负载均衡
 4.配置集群,将tomcat1,tomcat2都做如下配置
  
把server.xml中注释部分   
<!--   <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>-->   
替换如下cluster配置内容:   
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"  
                 channelSendOptions="8">   
          <!--     
             
          <Manager className="org.apache.catalina.ha.session.BackupManager"  
                    expireSessionsOnShutdown="false"  
                    notifyListenersOnReplication="true"  
                    mapSendOptions="8"/> -->   
          <!--   -->   
          <Manager className="org.apache.catalina.ha.session.DeltaManager"  
                   expireSessionsOnShutdown="false"  
                   notifyListenersOnReplication="true"/>   
  
          <Channel className="org.apache.catalina.tribes.group.GroupChannel">   
            <Membership className="org.apache.catalina.tribes.membership.McastService"  
                        address="228.0.0.4"  
                        port="45564"  
                        frequency="500"  
                        dropTime="3000"/>   
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"  
                      address="auto"  
                      port="4000"  
                      autoBind="100"  
                      selectorTimeout="5000"  
                      maxThreads="6"/>   
            <!-- timeout="60000"-->   
            <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">   
              <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />   
            </Sender>   
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>   
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>   
         <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>   
          </Channel>   
  
          <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"  
                 filter=""/>   
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>   
  
            <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>   
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>   
        </Cluster>
   
    在测试项目的web.xml中加入<distributable/>参数,
    distributable元素来告诉servlet/JSP容器,编写将在分布式Web容器中部署的应用。
   
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
	xmlns="http://java.sun.com/xml/ns/j2ee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
   <distributable/>
</web-app>
   

你可能感兴趣的:(apache,tomcat,Web,xml,jsp)