下載apache
          http://apache.mirror.phpchina.com/httpd/httpd-2.2.9-win32-src.zip
          下載mod_jk-1.2.26-httpd-2.2.4.so
          http://apache.mirror.phpchina.com/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.26/
          下載tomcat6
          下載JDK6
          然后配置好環(huán)境。

          步驟1:
          安裝apache,然后測試
          http://localhost:80/,可以顯示的話表示apache安裝成功。
          把mod_jk-1.2.26-httpd-2.2.4.so 改名為mod_jk,并復制到apache的安裝目錄的modules下。

          步驟2:
          修改apache,conf目錄下的httpd文件,增加以下內(nèi)容(根據(jù)自己的情況增減)

          LoadModule jk_module modules/mod_jk.so
          JkWorkersFile "C:\Program Files/Apache Software Foundation/Apache2.2/conf/workers.properties"
          JkLogFile "C:\Program Files/Apache Software Foundation/Apache2.2/logs/mod_jk.log"
          JkLogLevel severe

          JkMount /*.do controller
          JkMount /*.jsp controller
          JkMount /WEB-INF/* controller
          JkMount /lzj1/*.do controller


          步驟3:
          在conf目錄下增加uriworkermap.properties文件
          再增加workers.properties文件,增加或修改以下內(nèi)容(根據(jù)自己的情況而定)

          workers.tomcat_home="E:\java\apache-tomcat-6.0.16\apache-tomcat-6.0.16"
          workers.java_home="C:\Program Files\Java\jdk1.6.0_06"

          worker.list=controller,tomcat1,tomcat2

          worker.tomcat1.host=192.168.10.55
          worker.tomcat1.port=8009

          worker.tomcat2.port=8009
          worker.tomcat2.host=localhostworker.controller.type=lb

          worker.controller.balanced_workers=tomcat1,tomcat2 
          worker.controller.sticky_session=1
          worker.ajp13.lbfactor=1


          worker.ajp13.port=8009
          worker.ajp13.host=localhost
          worker.ajp13.type=ajp13

          worker.ajp13.lbfactor=1

          這樣就完成了均衡負載的配置。

          步驟4:
          配置tomcat6
          <Engine name="Standalone" defaultHost="localhost" jvmRoute="tomcat2">
          再配置tomcat6集群的session復制。打開tomcat6,conf目錄下的server.xml文件。把集群配置的注釋去掉。變成

          <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
                           channelSendOptions="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"/>

                      <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"/>
                    </Channel>

                    <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
                           filter=""/>
                    <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

                    <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                              tempDir="/tmp/war-temp/"
                              deployDir="/tmp/war-deploy/"
                              watchDir="/tmp/war-listen/"
                              watchEnabled="false"/>

                    <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
                    <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
                  </Cluster>


          步驟5:
          建立一個頁面index.jsp:

          /*<%
             System.out.println("===========================");
          %>
          */

          <%@ page contentType="text/html; charset=GBK" %>
          <%@ page import="java.util.*" %>
          <html><head><title>Cluster App Test</title></head>
          <body>
          Server Info:
          <%
          out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"<br>");%>
          <%
            out.println("<br> ID " + session.getId()+"<br>");
            // 如果有新的 Session 屬性設置
            String dataName = request.getParameter("dataName");
            if (dataName != null && dataName.length() > 0) {
               String dataValue = request.getParameter("dataValue");
               session.setAttribute(dataName, dataValue);
            }
            out.print("<b>Session 列表</b>");
            Enumeration e = session.getAttributeNames();
            while (e.hasMoreElements()) {
               String name = (String)e.nextElement();
               String value = session.getAttribute(name).toString();
               out.println( name + " = " + value+"<br>");
                   System.out.println( name + " = " + value);
             }
          %>
            <form action="index.jsp" method="POST">
              名稱:<input type=text size=20 name="dataName">
               <br>
              值:<input type=text size=20 name="dataValue">
               <br>
              <input type=submit>
             </form>
          </body>
          </html>

          其web.xml配置
          <distributable/>

          步驟6:
          最后使用jmeter運行一下簡單測試,設置40個并發(fā)用戶,測試的IP地址是192.168.10.66(apache)、192.168.10.66(tomcat2)、192.168.10.55(tomcat1)其中tomcat2是有線接入,tomcat2是無線接入。測試頁面為/lzj1/index.jsp。
          可以看看結(jié)果:
          tomcat1:

          Thread Name: 線程組 1-1
          Sample Start: 2008-07-13 22:32:42 CST
          Load time: 2532
          Latency: 2532
          Size in bytes: 401
          Sample Count: 1
          Error Count: 0
          Response code: 200
          Response message: OK

          Response headers:
          HTTP/1.1 200 OK
          Date: Sun, 13 Jul 2008 14:32:42 GMT
          Server: Apache/2.2.9 (Win32) mod_jk/1.2.26
          Set-Cookie: JSESSIONID=6A15C0175A2E1EC8E0930FAF0C28ADC9.tomcat1; Path=/lzj1

          tomcat2:

          Thread Name: 線程組 1-3
          Sample Start: 2008-07-13 22:32:44 CST
          Load time: 4
          Latency: 4
          Size in bytes: 401
          Sample Count: 1
          Error Count: 0
          Response code: 200
          Response message: OK

          Response headers:
          HTTP/1.1 200 OK
          Date: Sun, 13 Jul 2008 14:32:44 GMT
          Server: Apache/2.2.9 (Win32) mod_jk/1.2.26
          Set-Cookie: JSESSIONID=2FF347B788690651E7DADE1A040EE94C.tomcat2; Path=/lzj1

          可以從結(jié)果看到檢測到的服務器是Apache/2.2.9 (Win32) ,使用了mod_jk/1.2.26,并且tomcat1的反應時間明顯慢于tomcat2,這是由于這里的tomcat1的網(wǎng)絡是使用的是無線接入的緣故。

          posted on 2008-07-13 22:11 lzj520 閱讀(955) 評論(0)  編輯  收藏 所屬分類: 個人學習日記
          主站蜘蛛池模板: 郁南县| 改则县| 乐安县| 会东县| 崇义县| 镇安县| 西和县| 屯留县| 柳林县| 萝北县| 望奎县| 昭苏县| 昌宁县| 马鞍山市| 泰顺县| 遂昌县| 米林县| 虹口区| 镇原县| 牡丹江市| 越西县| 如东县| 丹棱县| 介休市| 阳新县| 曲松县| 兴和县| 鄢陵县| 晋宁县| 定边县| 辛集市| 涡阳县| 抚州市| 镇江市| 铜陵市| 综艺| 秀山| 忻城县| 漯河市| 白沙| 晋宁县|