Tomcat for Windows集羣

(一)環境說明
(1)服務器有1臺,分別解壓tomcat軟件至c:\tomcat1,c:\tomcat2,c:\tomcat3
(2)apache2.0.63、tomcat5.5.26、jk2.0.4、jdk1.4.2
(3)IP配置:tomcat的服務器IP爲192.168.0.1
(二)安裝過程
(1)在安裝tomcat的服務器上先安裝jdk
(2)配置jdk的安裝路徑,在環境變量path中加入jdk的bin路徑,新建環境變量JAVA_HOME指向jdk的安裝路徑[n1] 
(3)tomcat的默認WEB服務端口是8080,默認的模式是單獨服務,我的三個tomcat的WEB服務端口修改爲7777/8888/9999
(4)調試tomcat到能夠正常啓動修改位置爲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="7777"maxHttpHeaderSize="8192"
              maxThreads="150" minSpareThreads="25"maxSpareThreads="75"
              enableLookups="false" redirectPort="8443"acceptCount="100"
              connectionTimeout="20000" disableUploadTimeout="true" />
依次修改每個tomcat的監聽端口(7777/8888/9999)

同理修改:
AJP 1.3 Connector的端口號分別改爲:8009/8019/8029
Server port 端口號分別改爲:8005/8015/8025
(5)分別測試每個tomcat的啓動是否正常
http://192.168.0.1:7777
http://192.168.0.1:8888
http://192.168.0.1:9999
(三)負載均衡配置過程
(1)在那臺要安裝apache的服務器上安裝apache2.0.63,安裝路徑爲默認C:\ProgramFiles\Apache Group\Apache2
(2)安裝後測試apache能否正常啓動,調試到能夠正常啓動http://192.168.0.8080
(3)下載jk2.0.4後解壓縮文件
(4)將解壓縮後的目錄中的modules目錄中的mod_jk2.so文件複製到apache的安裝目錄下的modules目錄中,我的爲C:\ProgramFiles\Apache Group\Apache2\modules
(5)修改apache的安裝目錄中的conf目錄的配置文件httpd.conf,在文件中加LoadModule模塊配置信息的最後加上一句LoadModule jk2_module modules/mod_jk2.so
(6)分別修改三個tomcat的配置文件conf/server.xml,修改內容如下
修改前
    <!-- An Engine represents the entry point (withinCatalina) that processes
         every request.  TheEngine implementation for Tomcat stand alone
         analyzes the HTTP headersincluded with the request, and passes them
         on to the appropriate Host(virtual host). -->
    <!-- You should set jvmRoute to supportload-balancing via AJP ie :
    <Engine name="Standalone"defaultHost="localhost" jvmRoute="jvm1">        
    -->        
    <!-- Define the top level container in our containerhierarchy -->
    <Engine name="Catalina"defaultHost="localhost">
修改後
    <!-- An Engine represents the entry point (withinCatalina) that processes
         every request.  TheEngine implementation for Tomcat stand alone
         analyzes the HTTP headersincluded with the request, and passes them
         on to the appropriate Host(virtual host). -->
    <!-- You should set jvmRoute to supportload-balancing via AJP ie :-->
    <Engine name="Standalone"defaultHost="localhost" jvmRoute="tomcat1">                
    <!-- Define the top level container in our containerhierarchy
    <Engine name="Catalina"defaultHost="localhost">
    -->
將其中的jvmRoute="jvm1"分別修改爲jvmRoute="tomcat1"和jvmRoute="tomcat2"和jvmRoute="tomcat3"
(7)然後重啓三個tomcat,調試能夠正常啓動。
(8)在apache的安裝目錄中的conf目錄下創建文件workers2.properties,寫入文件內容如下
# fine the communication channel
[channel.socket:192.168.0.1:8009]
info=Ajp13 forwarding over socket
#配置第一個服務器
tomcatId=tomcat1 #要和tomcat的配置文件server.xml中的jvmRoute="tomcat1"名稱一致
debug=0
lb_factor=1 #負載平衡因子,數字越大請求被分配的機率越高
# Define the communication channel
[channel.socket:192.168.0.1:8019]
info=Ajp13 forwarding over socket
tomcatId=tomcat2
debug=0
lb_factor=1
# Define the communication channel
[channel.socket:192.168.0.1:8029]
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)在三個tomcat的安裝目錄中的webapps建立相同的應用,應用目錄名爲ydata,
(10)重啓apache服務器和三個tomcat服務器,到此負載 均衡已配置完成。測試負載均衡先測試apache,訪問http://192.168.0.1:8080/jkstatus.jsp
能否正常訪問,並查詢其中的內容,有三個tomcat的相關配置信息和負載說明,訪問http://192.168.0.1:8080/ydata看能夠運行,
能運行,則已建立負載均衡。
(四)tomcat集羣配置
(1)負載均衡配置的條件下配置tomcat集羣
(2)分別修改三個tomcat的配置文件conf/server.xml,修改內容如下
修改前
        <!--
        <ClusterclassName="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"/>
            <ValveclassName="org.apache.catalina.cluster.tcp.ReplicationValve"
                  filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>          
            <DeployerclassName="org.apache.catalina.cluster.deploy.FarmWarDeployer"
                      tempDir="/tmp/war-temp/"
                      deployDir="/tmp/war-deploy/"
                      watchDir="/tmp/war-listen/"
                      watchEnabled="false"/>                      
            <ClusterListenerclassName="org.apache.catalina.cluster.session.ClusterSessionListener"/>
        </Cluster>
        -->  
修改後

        <ClusterclassName="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"/>
            <ValveclassName="org.apache.catalina.cluster.tcp.ReplicationValve"
                  filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>                  
            <DeployerclassName="org.apache.catalina.cluster.deploy.FarmWarDeployer"
                      tempDir="/tmp/war-temp/"
                      deployDir="/tmp/war-deploy/"
                      watchDir="/tmp/war-listen/"
                      watchEnabled="false"/>                      
            <ClusterListenerclassName="org.apache.catalina.cluster.session.ClusterSessionListener"/>
        </Cluster>    
將集羣配置選項的註釋放開即可,如上。
部署應用的WEB-INF\web.xml的倒數第二行中增加<distributable/>

(3)重啓三個tomcat。到此tomcat的集羣已配置完成。

另:如果是安裝tomcat集羣的機器上有多個網卡,那麼需要在修改conf/server.xml時,做如下修改:(與單網卡相比,修改瞭如下內容中的粉紅色標記的內容,填寫機器的IP地址)
分別修改三個tomcat的配置文件conf/server.xml,修改內容如下
修改前
        <!--
        <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"/>
            <ValveclassName="org.apache.catalina.cluster.tcp.ReplicationValve"
                  filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>          
            <DeployerclassName="org.apache.catalina.cluster.deploy.FarmWarDeployer"
                      tempDir="/tmp/war-temp/"
                      deployDir="/tmp/war-deploy/"
                      watchDir="/tmp/war-listen/"
                      watchEnabled="false"/>                      
            <ClusterListenerclassName="org.apache.catalina.cluster.session.ClusterSessionListener"/>
        </Cluster>
        -->  
修改後

        <ClusterclassName="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"

        mcastBindAddress="192.168.0.1"
                mcastAddr="228.0.0.4"
                mcastPort="45564"
                mcastFrequency="500"
                mcastDropTime="3000"/>
            <Receiver
                className="org.apache.catalina.cluster.tcp.ReplicationListener"
                tcpListenAddress="192.168.0.1"
                tcpListenPort="4001"
                tcpSelectorTimeout="100"
                tcpThreadCount="6"/>

            <Sender
                className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
                replicationMode="pooled"
                ackTimeout="5000"/>
            <ValveclassName="org.apache.catalina.cluster.tcp.ReplicationValve"
                  filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>                  
            <DeployerclassName="org.apache.catalina.cluster.deploy.FarmWarDeployer"
                      tempDir="/tmp/war-temp/"
                      deployDir="/tmp/war-deploy/"
                      watchDir="/tmp/war-listen/"
                      watchEnabled="false"/>                      
            <ClusterListenerclassName="org.apache.catalina.cluster.session.ClusterSessionListener"/>
        </Cluster> 

 [n1]或者直接在startup.bat文件中加入環境變量配置,如:set JAVA_HOME=C:\j2sdk1.4.2_13

 

發佈了0 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章