輕松實(shí)現(xiàn)Apache,Tomcat集群和負(fù)載均衡_第1頁(yè)
輕松實(shí)現(xiàn)Apache,Tomcat集群和負(fù)載均衡_第2頁(yè)
輕松實(shí)現(xiàn)Apache,Tomcat集群和負(fù)載均衡_第3頁(yè)
輕松實(shí)現(xiàn)Apache,Tomcat集群和負(fù)載均衡_第4頁(yè)
輕松實(shí)現(xiàn)Apache,Tomcat集群和負(fù)載均衡_第5頁(yè)
已閱讀5頁(yè),還剩16頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、輕松實(shí)現(xiàn)Apache,Tomcat集群和負(fù)載均衡0, 環(huán)境說明Apache :apache_2.0.55 1 個(gè)Tomcat: apache-tomcat-5.5.17 (zip版) 2個(gè)mod_jk: mod_jk-apache-2.0.55.so 1個(gè)第一部分:負(fù)載均衡負(fù)載均衡,就是apache將客戶請(qǐng)求均衡的分給tomcat1,tomcat2.去處理1.安裝apche,tomcat/ 下載Apache 2.0.55/download-55.cgi 下載tomcat5.5 zip版本(解壓即可,綠色版

2、 /tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.15/ 下和 apache版本匹配按照jdk,我的路徑為:E:ideapacheApache2解壓兩份Tomcat, 路徑分別為E:idetomcat1,E:idetomcat2下載mod_jk2.修改Apache配置文件http.conf在apache安裝目錄下conf目錄中找到http.conf 在文件最后加上下面一句話就可以了include "E:ideapacheApache2confmod_jk.conf"2. ht

3、tp.conf 同目錄下新建mod_jk.conf文件,內(nèi)容如下#加載mod_jk ModuleLoadModule jk_module modules/mod_jk-apache-2.0.55.so#指定 perties文件路徑JkWorkersFile conf/perties#指定那些請(qǐng)求交給tomcat處理,"controller"為在pertise里指定的負(fù)載分配控制器JkMount /*.jsp controller3.在http.conf同目錄下新建 perties文件,內(nèi)

4、容如下worker.list = controller,tomcat1,tomcat2 #server 列表#=tomcat1=worker.tomcat1.port=8009 #ajp13 端口號(hào),在tomcat下server.xml配置,默認(rèn)8009 worker.tomcat1.host=localhost #tomcat的主機(jī)地址,如不為本機(jī),請(qǐng)?zhí)顚慽p地址 worker.tomcat1.type=ajp13worker.tomcat1.lbfactor = 1 #server的加權(quán)比重,值越高,分得的請(qǐng)求越多#=tomcat2=worker.tomcat2.port=9009 #aj

5、p13 端口號(hào),在tomcat下server.xml配置,默認(rèn)8009 worker.tomcat2.host=localhost #tomcat的主機(jī)地址,如不為本機(jī),請(qǐng)?zhí)顚慽p地址 worker.tomcat2.type=ajp13worker.tomcat2.lbfactor = 1 #server的加權(quán)比重,值越高,分得的請(qǐng)求越多#=controller,負(fù)載均衡控制器=worker.controller.type=lbworker.controller.balanced_workers=tomcat1,tomcat2 #指定分擔(dān)請(qǐng)求的tomcatworker.controller.s

6、ticky_session=14.修改tomcat配置文件server.xml如果你在不同電腦上安裝tomcat,tomcat的安裝數(shù)量為一個(gè),可以不必修改tomcat配置文件 我這里是在同一臺(tái)電腦上安裝兩個(gè)tomcat,所以需要更改其中一個(gè)的設(shè)置打開tomcat2/conf/server.xml文件5.編寫一個(gè)測(cè)試jsp建立一個(gè)目錄test.里面新建一個(gè)test.jsp,內(nèi)容為 <%System.out.println("="); %>把test放到tomcat1,tomcat2的webapps下6.啟動(dòng)apache,tomcat1,tomcat2,進(jìn)行測(cè)試通

7、過 http:/localhost/test/test.jsp 訪問,查看tomcat1的窗口,可以看到打印了一行"=再刷新一次,tomcat2也打印了一條,再刷新,可以看到請(qǐng)求會(huì)被tomcat1,tomcat2輪流處理,實(shí)第二部分,配置集群只配置負(fù)載均衡還不行,還要session復(fù)制,也就是說其中任何一個(gè)tomcat的添加的sessio它tomcat, 集群內(nèi)的tomcat都有相同的session1. 修改tomcat1, tomcat2的server.xml,將集群部分配置的在注釋符刪掉,并將tomcat2的4001免與tomcat沖突,當(dāng)然,如果是兩臺(tái)電腦,是不用改端口的,去掉

8、注釋符即可2,修改測(cè)試項(xiàng)目test修改test.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() + " : &q

9、uot; + request.getLocalPort()+"<br>");%> <%out.println("<br> ID " + session.getId()+"<br>");/ 如果有新的 Session 屬性設(shè)置String dataName = request.getParameter("dataName");if (dataName != null && dataName.length() > 0) String dataValu

10、e = 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).toStri

11、ng();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=

12、"dataValue"><br><input type=submit></form></body></html>然后在test 新建WEB-INF目錄,WEB-INF下新建web.xml,內(nèi)容如下<web-app xmlns=" xmlns:xsi="/2001/XMxsi:schemaLocation=" <display-name>TomcatDemo</display-name><distributable

13、/></web-app>注意:在你的應(yīng)用的web.xml加入 <distributable/> 即可ok,講test復(fù)制到tomcat1,tomcat2的webapps下,重啟apache,tomcat1,tomcat2,輸入網(wǎng)址 http:/localhost/test/test.jsp新建一個(gè) 名稱為 xiaoluo ,值為 cdut 的session,提交查詢,新開一個(gè)ie窗口,再提交查詢,個(gè)tomcat 是負(fù)載均衡,并且session同步的Tomcat1:<?xml version='1.0' encoding='utf-8&

14、#39;?><!-Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the &quo

15、t;License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"

16、BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.-><!- Note: A "Server" is not itself a "Container", so you may not define subcomponents such as &

17、quot;Valves" at this level.Documentation at /docs/config/server.html-><Server port="8005" shutdown="SHUTDOWN"><!-APR library loader. Documentation at /docs/apr.html -><Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine=&q

18、uot;on" <!-Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-ho <Listener className="org.apache.catalina.core.JasperListener" /><!- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html - <Listener className="org.apa

19、che.catalina.mbeans.ServerLifecycleListener" /><Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /<!- Global JNDI resourcesDocumentation at /docs/jndi-resources-howto.html-><GlobalNamingResources><!- Editable user database that can

20、also be used byUserDatabaseRealm to authenticate users-><Resource name="UserDatabase" auth="Container"type="org.apache.catalina.UserDatabase"description="User database that can be updated and saved"factory="org.apache.catalina.users.MemoryUserDataba

21、seFactory" pathname="conf/tomcat-users.xml" /></GlobalNamingResources><!- A "Service" is a collection of one or more "Connectors" that sharea single "Container" Note: A "Service" is not itself a "Container", so you may not

22、define subcomponents such as "Valves" at this level. Documentation at /docs/config/service.html-><Service name="Catalina"><!-The connectors can use a shared executor, you can define one or more named th <!-<Executor name="tomcatThreadPool" namePrefix=&

23、quot;catalina-exec-"maxThreads="150" minSpareThreads="4"/>-><!- A "Connector" represents an endpoint by which requests are received and responses are returned. Documentation at :Java HTTP Connector: /docs/config/http.html (blocking & non-blocking) Java

24、 AJP Connector: /docs/config/ajp.htmlAPR (HTTP/AJP) Connector: /docs/apr.htmlDefine a non-SSL HTTP/1.1 Connector on port 8080-><Connector port="8080" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" /><!- A "Connector" usin

25、g the shared thread pool-><!-<Connector executor="tomcatThreadPool"port="8080" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" />-><!- Define a SSL HTTP/1.1 Connector on port 8443This connector uses the JSSE configur

26、ation, when using APR, the connector should be using the OpenSSL style configurationdescribed in the APR documentation -><!-<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"maxThreads="150" scheme="https" secure="true"cl

27、ientAuth="false" sslProtocol="TLS" />-><!- Define an AJP 1.3 Connector on port 8009 -><Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /><!- An Engine represents the entry point (within Catalina) that processes every

28、 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).Documentation at /docs/config/engine.html -><!- You should set jvmRoute to support load-balancing via AJP ie :<Engine nam

29、e="Standalone" defaultHost="localhost" jvmRoute="jvm1"> -><Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1"><!-For clustering, please take a look at documentation at:/docs/cluster-howto.html (simple how to)/d

30、ocs/config/cluster.html (reference documentation) -><!-<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> -><Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"channelSendOptions="6"><Manager className="org.apache

31、.catalina.ha.session.BackupManager" expireSessionsOnShutdown="false"notifyListenersOnReplication="true"mapSendOptions="6"/><!-<Manager className="org.apache.catalina.ha.session.DeltaManager"expireSessionsOnShutdown="false"notifyListener

32、sOnReplication="true"/>-><Channel className="org.apache.catalina.tribes.group.GroupChannel"><Membership className="org.apache.catalina.tribes.membership.McastService address=""port="45564"frequency="500"dropTime="300

33、0"/><Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver address="auto"port="4001"selectorTimeout="100"maxThreads="6"/><Sender className="org.apache.catalina.tribes.transport.ReplicationTransm <Transport class

34、Name="org.apache.catalina.tribes.transport.nio.PooledPa </Sender><Interceptor className="erceptors.Tcp <InterceptorclassName="erceptors.MessageDispatch15Interceptor <InterceptorclassName="org.a

35、erceptors.ThroughputInterceptor"/> </Channel><Valve className="org.apache.catalina.ha.tcp.ReplicationValve"filter=".*.gif;.*.js;.*.jpg;.*.png;.*.htm;.*.html;.*.css;.*.<Deployer className="org.apache.catalina.ha.deploy.FarmWarDepl

36、oyer" tempDir="/tmp/war-temp/"deployDir="/tmp/war-deploy/"watchDir="/tmp/war-listen/"watchEnabled="false"/><ClusterListener className="org.apache.catalina.ha.session.ClusterSessionLi</Cluster><!- The request dumper valve dumps useful d

37、ebugging information about the request and response data received and sent by Tomcat.Documentation at: /docs/config/valve.html -><!-<Valve className="org.apache.catalina.valves.RequestDumperValve"/>-><!- This Realm uses the UserDatabase configured in the global JNDIresour

38、ces under the key "UserDatabase". Any editsthat are performed against this UserDatabase are immediatelyavailable for use by the Realm. -><Realm className="org.apache.catalina.realm.UserDatabaseRealm"resourceName="UserDatabase"/><!- Define the default virtual

39、 hostNote: XML Schema validation will not work with Xerces 2.2.-><Host name="localhost" appBase="webapps"unpackWARs="true" autoDeploy="true"xmlValidation="false" xmlNamespaceAware="false"><!- SingleSignOn valve, share authentica

40、tion between web applications Documentation at: /docs/config/valve.html -><!-<Valve className="org.apache.catalina.authenticator.SingleSignOn" /> -><!- Access log processes all example.Documentation at: /docs/config/valve.html -><!-<Valve className="org.apac

41、he.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="common" resolveH -></Host></Engine></Service></Server>Tomcat2<?xml version='1.0' encoding='utf-8'?>&

42、lt;!-Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0 (the "License&quo

43、t;); you may not use this file except in compliance withthe License. You may obtain a copy of the License at/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT W

44、ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.-><!- Note: A "Server" is not itself a "Container", so you may notdefine subcomponents such as "Valves"

45、at this level.Documentation at /docs/config/server.html-><Server port="9005" shutdown="SHUTDOWN"><!-APR library loader. Documentation at /docs/apr.html -><Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

46、<!-Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -><Listener className="org.apache.catalina.core.JasperListener" /><!- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -><Listener className="org.

47、apache.catalina.mbeans.ServerLifecycleListener" /> <ListenerclassName="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /><!- Global JNDI resourcesDocumentation at /docs/jndi-resources-howto.html-><GlobalNamingResources><!- Editable user database th

48、at can also be used byUserDatabaseRealm to authenticate users-><Resource name="UserDatabase" auth="Container"type="org.apache.catalina.UserDatabase"description="User database that can be updated and saved"factory="org.apache.catalina.users.MemoryUse

49、rDatabaseFactory" pathname="conf/tomcat-users.xml" /></GlobalNamingResources><!- A "Service" is a collection of one or more "Connectors" that sharea single "Container" Note: A "Service" is not itself a "Container", so you m

50、ay not define subcomponents such as "Valves" at this level. Documentation at /docs/config/service.html-><Service name="Catalina"><!-The connectors can use a shared executor, you can define one or more named thread pools-><!-<Executor name="tomcatThreadPo

51、ol" namePrefix="catalina-exec-" maxThreads="150" minSpareThreads="4"/>-><!- A "Connector" represents an endpoint by which requests are received and responses are returned. Documentation at :Java HTTP Connector: /docs/config/http.html (blocking &a

52、mp; non-blocking) Java AJP Connector: /docs/config/ajp.htmlAPR (HTTP/AJP) Connector: /docs/apr.htmlDefine a non-SSL HTTP/1.1 Connector on port 8080-><Connector port="9080" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" /><!- A &quo

53、t;Connector" using the shared thread pool-><!-<Connector executor="tomcatThreadPool"port="8080" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" />-><!- Define a SSL HTTP/1.1 Connector on port 8443This connector

54、uses the JSSE configuration, when using APR, the connector should be using the OpenSSL style configurationdescribed in the APR documentation -><!-<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"maxThreads="150" scheme="https" sec

55、ure="true"clientAuth="false" sslProtocol="TLS" />-><!- Define an AJP 1.3 Connector on port 8009 -><Connector port="9009" protocol="AJP/1.3" redirectPort="8443" /><!- An Engine represents the entry point (within Catalina

56、) 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).Documentation at /docs/config/engine.html -><!- You should set jvmRoute to support load-balancing via

57、AJP ie :<Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1"> -><Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2"><!-For clustering, please take a look at documentation at:/docs/cluster-howto.

58、html (simple how to)/docs/config/cluster.html (reference documentation) -><!-<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>-><Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"channelSendOptions="6"><Manager class

59、Name="org.apache.catalina.ha.session.BackupManager" expireSessionsOnShutdown="false"notifyListenersOnReplication="true"mapSendOptions="6"/><!-<Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="fal

60、se"notifyListenersOnReplication="true"/>-><Channel className="org.apache.catalina.tribes.group.GroupChannel"> <MembershipclassName="org.apache.catalina.tribes.membership.McastService"address=""port="45564"frequency="

61、500"dropTime="3000"/><ReceiverclassName="org.apache.catalina.tribes.transport.nio.NioReceiver"address="auto"port="4002"selectorTimeout="100"maxThreads="6"/><SenderclassName="org.apache.catalina.tribes.transport.Replica

62、tionTransmitter"> <TransportclassName="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/> </Sender><InterceptorclassName="erceptors.TcpFailureDetector"/> <InterceptorclassName="org.apache.catalina

63、.erceptors.MessageDispatch15Interceptor"/><InterceptorclassName="erceptors.ThroughputInterceptor"/> </Channel><Valve className="org.apache.catalina.ha.tcp.ReplicationValve"filter=".*.gif;.*.js;.*.jpg;

64、.*.png;.*.htm;.*.html;.*.css;.*.txt;"/><DeployerclassName="org.apache.catalina.ha.deploy.FarmWarDeployer"tempDir="/tmp/war-temp/"deployDir="/tmp/war-deploy/"watchDir="/tmp/war-listen/"watchEnabled="false"/><ClusterListenerclassName=&

65、quot;org.apache.catalina.ha.session.ClusterSessionListener"/></Cluster><!- The request dumper valve dumps useful debugging information about the request and response data received and sent by Tomcat.Documentation at: /docs/config/valve.html -><!-<Valve className="org.a

66、pache.catalina.valves.RequestDumperValve"/>-><!- This Realm uses the UserDatabase configured in the global JNDI resources under the key "UserDatabase". Any editsthat are performed against this UserDatabase are immediately available for use by the Realm. -><Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/><!- Define the default virtual hostNote: X

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論