<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 1, 文章 - 44, 評(píng)論 - 2, 引用 - 0
    數(shù)據(jù)加載中……

    實(shí)踐中整理出tomcat集群和負(fù)載均衡

    (一)環(huán)境說明
    (1)服務(wù)器有4臺(tái),一臺(tái)安裝apache,三臺(tái)安裝tomcat
    (2)apache2.0.55、tomcat5.5.15、jk2.0.4、jdk1.5.6或jdk1.4.2
    (3)ip配置,一臺(tái)安裝apache的ip為192.168.0.88,三臺(tái)安裝tomcat的服務(wù)器ip分別為192.168.0.1/2/4


    (二)安裝過程
    (1)在三臺(tái)要安裝tomcat的服務(wù)器上先安裝jdk
    (2)配置jdk的安裝路徑,在環(huán)境變量path中加入jdk的bin路徑,新建環(huán)境變量JAVA_HOME指向jdk的安裝路徑
    (3)在三臺(tái)要安裝tomcat的服務(wù)器上分別安裝tomcat,調(diào)試三個(gè)tomcat到能夠正常啟動(dòng)
    (4)tomcat的默認(rèn)WEB服務(wù)端口是8080,默認(rèn)的模式是單獨(dú)服務(wù),我的三個(gè)tomcat的WEB服務(wù)端口修改為7080/8888/9999
    修改位置為tomcat的安裝目錄下的conf/server.xml
    修改前的配置為

    ????<Connector port="8080" maxHttpHeaderSize="8192"
    ?????????????? maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
    ?????????????? enableLookups="false" redirectPort="8443" acceptCount="100"
    ?????????????? connectionTimeout="20000" disableUploadTimeout="true" />



    修改后的配置為

    ????<Connector port="7080" maxHttpHeaderSize="8192"
    ?????????????? maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
    ?????????????? enableLookups="false" redirectPort="8443" acceptCount="100"
    ?????????????? connectionTimeout="20000" disableUploadTimeout="true" />



    依次修改每個(gè)tomcat的監(jiān)聽端口(7080/8888/9999)

    (5)分別測(cè)試每個(gè)tomcat的啟動(dòng)是否正常
    http://192.168.0.1:7080
    http://192.168.0.2:8888
    http://192.168.0.4:9999


    (三)負(fù)載均衡配置過程
    (1)在那臺(tái)要安裝apache的服務(wù)器上安裝apache2.0.55,我的安裝路徑為默認(rèn)C:\Program Files\Apache Group\Apache2
    (2)安裝后測(cè)試apache能否正常啟動(dòng),調(diào)試到能夠正常啟動(dòng)http://192.168.0.88
    (3)下載jk2.0.4后解壓縮文件
    (4)將解壓縮后的目錄中的modules目錄中的mod_jk2.so文件復(fù)制到apache的安裝目錄下的modules目錄中,我的為C:\Program Files\Apache Group\Apache2\modules
    (5)修改apache的安裝目錄中的conf目錄的配置文件httpd.conf,在文件中加LoadModule模塊配置信息的最后加上一句LoadModule jk2_module modules/mod_jk2.so
    (6)分別修改三個(gè)tomcat的配置文件conf/server.xml,修改內(nèi)容如下
    修改前

    ????<!-- An Engine represents the entry point (within Catalina) that processes
    ???????? every request.??The Engine implementation for Tomcat stand alone
    ???????? analyzes the HTTP headers included with the request, and passes them
    ???????? on to the appropriate Host (virtual host). -->

    ????<!-- You should set jvmRoute to support load-balancing via AJP ie :
    ????<Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">????????
    ????-->
    ????????
    ????<!-- Define the top level container in our container hierarchy -->
    ????<Engine name="Catalina" defaultHost="localhost">

    修改后

    ????<!-- An Engine represents the entry point (within Catalina) that processes
    ???????? every request.??The Engine implementation for Tomcat stand alone
    ???????? analyzes the HTTP headers included with the request, and passes them
    ???????? on to the appropriate Host (virtual host). -->

    ????<!-- You should set jvmRoute to support load-balancing via AJP ie :-->
    ????<Engine name="Standalone" defaultHost="localhost" jvmRoute="tomcat1">????????
    ????
    ????????
    ????<!-- Define the top level container in our container hierarchy
    ????<Engine name="Catalina" defaultHost="localhost">
    ????-->


    將其中的jvmRoute="jvm1"分別修改為jvmRoute="tomcat1"和jvmRoute="tomcat2"和jvmRoute="tomcat3"

    (7)然后重啟三個(gè)tomcat,調(diào)試能夠正常啟動(dòng)。
    (8)在apache的安裝目錄中的conf目錄下創(chuàng)建文件workers2.propertie,寫入文件內(nèi)容如下

    # fine the communication channel
    [channel.socket:192.168.0.1:8009]
    info=Ajp13 forwarding over socket


    #配置第一個(gè)服務(wù)器
    tomcatId=tomcat1 #要和tomcat的配置文件server.xml中的jvmRoute="tomcat1"名稱一致
    debug=0
    lb_factor=1 #負(fù)載平衡因子,數(shù)字越大請(qǐng)求被分配的幾率越高

    # Define the communication channel
    [channel.socket:192.168.0.2:8009]
    info=Ajp13 forwarding over socket
    tomcatId=tomcat2
    debug=0
    lb_factor=1

    # Define the communication channel
    [channel.socket:192.168.0.4:8009]
    info=Ajp13 forwarding over socket
    tomcatId=tomcat3
    debug=0
    lb_factor=1

    [status:]
    info=Status worker, displays runtime information.??

    [uri:/jkstatus.jsp]
    info=Display status information and checks the config file for changes.
    group=status:

    [uri:/*]
    info=Map the whole webapp
    debug=0


    (9)在三個(gè)tomcat的安裝目錄中的webapps建立相同的應(yīng)用,我和應(yīng)用目錄名為TomcatDemo,在三個(gè)應(yīng)用目錄中建立相同 WEB-INF目錄和頁面index.jsp,index.jsp的頁面內(nèi)容如下

    <%@ 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 屬性設(shè)置
    ??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>


    (10)重啟apache服務(wù)器和三個(gè)tomcat服務(wù)器,到此負(fù)載 均衡已配置完成。測(cè)試負(fù)載均衡先測(cè)試apache,訪問http://192.168.0.88/jkstatus.jsp
    能否正常訪問,并查詢其中的內(nèi)容,有三個(gè)tomcat的相關(guān)配置信息和負(fù)載說明,訪問http://192.168.0.88/TomcatDemo/index.jsp看能夠運(yùn)行,
    能運(yùn)行,則已建立負(fù)載均衡。


    (四)tomcat集群配置
    (1)負(fù)載均衡配置的條件下配置tomcat集群
    (2)分別修改三個(gè)tomcat的配置文件conf/server.xml,修改內(nèi)容如下
    修改前

    ???????<!--
    ????????<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="5000"/>

    ????????????<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>
    ????????-->??


    ?修改后

    ???????<!-- modify by whh -->
    ????????<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="5000"/>

    ????????????<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>
    ?????? <!-- modify by whh -->

    將集群配置選項(xiàng)的注釋放開即可,如上。
    (3)重啟三個(gè)tomcat。到此tomcat的集群已配置完成。

    (五)應(yīng)用配置
    對(duì)于要進(jìn)行負(fù)載和集群的的tomcat目錄下的webapps中的應(yīng)用中的WEB-INF中的web.xml文件要添加如下一句配置
    <distributable/>
    配置前

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app 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" version="2.4">
    ??<display-name>TomcatDemo</display-name>
    </web-app>


    配置后

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app 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" version="2.4">
    ??<display-name>TomcatDemo</display-name>
    ?? <distributable/>
    </web-app>

    posted on 2006-11-23 10:32 ASONG 閱讀(209) 評(píng)論(0)  編輯  收藏 所屬分類: 應(yīng)用服務(wù)器

    主站蜘蛛池模板: 亚洲永久精品ww47| 亚洲 暴爽 AV人人爽日日碰| 日韩精品无码一区二区三区免费| 久久精品亚洲AV久久久无码| 午夜国产大片免费观看| 国产羞羞的视频在线观看免费| 亚洲专区中文字幕| 亚洲精品偷拍视频免费观看| 色欲色香天天天综合网站免费 | 亚洲欧洲精品视频在线观看| 成人免费无码精品国产电影| 精品一卡2卡三卡4卡免费视频| 亚洲熟妇AV一区二区三区浪潮| 国产亚洲?V无码?V男人的天堂| 亚洲成年人免费网站| 人与动性xxxxx免费| 亚洲性色成人av天堂| 中文字幕亚洲一区二区三区| 欧美三级在线电影免费| 中文字幕无码免费久久9一区9| 亚洲一区二区三区在线观看网站| 亚洲午夜无码久久久久| 精品国产麻豆免费网站| 99在线在线视频免费视频观看| 人体大胆做受免费视频| 亚洲精品二三区伊人久久| 亚洲va久久久噜噜噜久久天堂| 全部免费国产潢色一级| 皇色在线视频免费网站| 久久青草国产免费观看| 免费国产va视频永久在线观看| 亚洲 暴爽 AV人人爽日日碰| 亚洲专区先锋影音| 亚洲女初尝黑人巨高清| 亚洲精品网站在线观看不卡无广告 | 亚洲尹人九九大色香蕉网站| 国产亚洲精久久久久久无码77777| 日韩激情淫片免费看| 国产成人免费网站| 精品国产sm捆绑最大网免费站| 国产免费一区二区三区不卡|