小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Tomcat群集配置

 figol 2006-09-14

 

Tomcat群集配置

 

作者:Figol(figolmail@gmail.com)

文章出處:www.

日期:2006-9-14

 

大型的企業(yè)應(yīng)用每天都需要承受巨大的訪問量,在著巨大訪問量的背后有數(shù)臺服務(wù)器支撐著,如果一臺服務(wù)器崩潰了,那么其他服務(wù)器可以使企業(yè)應(yīng)用繼續(xù)運(yùn)行,用戶對服務(wù)器的運(yùn)作是透明化的,如何實(shí)現(xiàn)這種透明化呢?由如下問題需要解決。

一.Session的復(fù)制

二.如何將請求發(fā)送到正常的服務(wù)器

針對以上問題,可以使用群集和負(fù)載均衡來解決,整體架構(gòu)如下:

Figure 1
(圖片來自:)

中間由一臺服務(wù)器做負(fù)載均衡(Load Balancer),它將所有請求,根據(jù)一定的負(fù)載均衡規(guī)則發(fā)送給指定的群集服務(wù)器(Cluster),群集服務(wù)器擁有著相同的狀態(tài)和相同的應(yīng)用程序,并且他們的Session是相互復(fù)制的,這樣,不管訪問哪臺服務(wù)器都具有相同的結(jié)果,即使一臺服務(wù)器崩潰掉以后,可以由其他集群服務(wù)器繼續(xù)負(fù)責(zé)應(yīng)用程序的運(yùn)行。


 

Tomcat中如何配置群集

我們假設(shè)有如下場景,一臺負(fù)載均衡服務(wù)器負(fù)責(zé)請求的均衡,群集服務(wù)器A和群集服務(wù)器B組成一個群集,當(dāng)某個群集服務(wù)器崩潰后,另外一臺繼續(xù)負(fù)責(zé)應(yīng)用程序的運(yùn)行。

一.           配置Tomcat5.5.12群集服務(wù)器A

修改Tomcat配置文件server.xml

1.群集服務(wù)器A的端口號與B不沖突,即使Server Port,Connector,Coyote/JK2 AJP Connector的端口號唯一

2.在Host元素下增加以下內(nèi)容:

<Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"

                 managerClassName="org.apache.catalina.cluster.session.DeltaManager"

                 expireSessionsOnShutdown="false"

                 useDirtyFlag="true"

                 notifyListenersOnReplication="true">

                  <!--每個群集服務(wù)器都需要有相同的Membership配置-->

            <Membership

                className="org.apache.catalina.cluster.mcast.McastService"

                mcastAddr="228.0.0.4"

                mcastPort="45564"

                mcastFrequency="500"

                mcastDropTime="3000"/>

           <!--tcpListenAddress:本機(jī)IP地址 服務(wù)器將此地址廣播給其他群集服務(wù)器-->

            <Receiver

                className="org.apache.catalina.cluster.tcp.ReplicationListener"

                tcpListenAddress="10.10.13.145"

                tcpListenPort="4001"

                tcpSelectorTimeout="100"

                tcpThreadCount="6"/>

 

            <Sender

                className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"

                replicationMode="pooled"

                ackTimeout="15000"

                waitForAck="true"/>

 

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

 

3.修改Web應(yīng)用程序配置文件web.xml

web.xml文件中<web-app>元素下增加以下內(nèi)容:

<!--此應(yīng)用將與群集服務(wù)器復(fù)制Session-->

     <distributable/>

 

二.           配置Tomcat5.5.12群集服務(wù)器B

與群集服務(wù)器A配置基本相同,唯一不同的地方就是server.xml文件中

<Receiver

                className="org.apache.catalina.cluster.tcp.ReplicationListener"

                tcpListenAddress="10.10.13.145"

                tcpListenPort="4002"

                tcpSelectorTimeout="100"

                tcpThreadCount="6"/>

tcpListenAddress應(yīng)為本機(jī)地址,如果兩臺群集服務(wù)器在一臺機(jī)器上,則端口號要不同

       注意:B的其他端口不要與A沖突。

三.           群集服務(wù)器具體配置結(jié)果

配置參數(shù)

群集服務(wù)器 A

群集服務(wù)器B

Server Port

9005

10005

Connector

9080

10080

Coyote/JK2 AJP Connector

9009

10009

Cluster mcastAddr

228.0.0.4

228.0.0.4

Cluster mcastPort

45564

45564

tcpListenAddress

本機(jī)IP地址

本機(jī)IP地址

Cluster tcpListenPort

4001

4002

Mcast* 用于廣播,所有群集服務(wù)器需要填寫相同的配置

tcpListen* 本機(jī)的IP,群集服務(wù)器啟動時,會將自己的IP和端口號廣播出去,其他群集服務(wù)器收到后,響應(yīng)廣播發(fā)出者。

 

四.           測試群集

啟動群集服務(wù)器A,再啟動群集服務(wù)器B會顯示群集服務(wù)器的信息,表示群集服務(wù)器配置成功

五.           配置負(fù)載均衡服務(wù)器Apache2.2.3

現(xiàn)在雖然群集已經(jīng)有了相同的狀態(tài),但需要不同的IP地址才能訪問到服務(wù)器AB,現(xiàn)在我們配置一臺負(fù)載均衡服務(wù)器來實(shí)現(xiàn)統(tǒng)一的入口訪問,和負(fù)載的均衡。

下載Apache服務(wù)器2.2.3。

修改httpd.conf文件

將以下Module的注釋去掉

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_balancer_module modules/mod_proxy_balancer.so

LoadModule proxy_http_module modules/mod_proxy_http.so

 

并增加以下元素

ProxyRequests Off

 

ProxyPass /helloworld balancer://mycluster stickysession=jsessionid nofailover=On

<Proxy balancer://mycluster>

BalancerMember http://10.10.13.145:9080

BalancerMember http://10.10.13.145:10080 smax=1 loadfactor=20

</Proxy>

 

 

<Location /balancer-manager>

SetHandler balancer-manager

 

Order Deny,Allow

Deny from all

Allow from all

</Location>

 

<Location /server-status>

SetHandler server-status

 

Order Deny,Allow

Deny from all

Allow from all

</Location>

 

其中

ProxyPass /helloworld balancer://mycluster stickysession=jsessionid nofailover=On

<Proxy balancer://mycluster>

BalancerMember http://10.10.13.145:9080

BalancerMember http://10.10.13.145:10080 smax=1 loadfactor=20

</Proxy>

ProxyPass為代理轉(zhuǎn)發(fā)的Url,即將所有訪問/helloworld的請求轉(zhuǎn)發(fā)到群集balancer://mycluster

BalancerMember為群集的成員,即群集服務(wù)器AB,負(fù)載均衡服務(wù)器會根據(jù)均衡規(guī)則來將請求轉(zhuǎn)發(fā)給BalancerMember。

 

配置好后,啟動Apahce服務(wù)器,訪問localhost/hellworld就會看到群集服務(wù)器中應(yīng)用返回的結(jié)果。恭喜你,負(fù)載均衡和群集已經(jīng)配置成功了。

 

參考文檔:

Clustering and Load Balancing in Tomcat 5, Part 1   by  Srini Penchikala

Clustering and Load Balancing in Tomcat 5, Part 2   by Srini Penchikala

Apache Tomcat 5.5 Document

Apache Http Server Document

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多