鍩轰簬mod_proxy+Apache 2.2.16+Tomcat 七鐨勮礋杞藉潎琛′笌闆嗙兢閰嶇疆

鍩轰簬mod_proxy+Apache 2.2.16+Tomcat 7鐨勮礋杞藉潎琛′笌闆嗙兢閰嶇疆

鍩轰簬mod_proxy+Apache 2.2.16+Tomcat 7鐨勮礋杞藉潎琛′笌闆嗙兢閰嶇疆聽
Peter Wei杞嚜銆?a href="http://peterwei.iteye.com/blog/757125">http://peterwei.iteye.com/blog/757125銆?/div>

鍩轰簬mod_proxy+Apache 2.2.16+Tomcat 7鐨勮礋杞藉潎琛′笌闆嗙兢閰嶇疆


鍛ㄦ棩鏅氬拰GF鐨勮€佷埂浠枬浜嗕簲绮恫锛屽鑷村懆涓€璧蜂笉浜嗗簥锛屽彧濂借鍋囧湪瀹剁潯瑙夈€傜櫧澶╃潯浜嗗崐澶╋紝鏅氫笂鑷劧鐫′笉鐫€瑙夈€傛濂界幇鍦ㄧ殑椤圭洰涓篃鐢ㄥ埌浜嗚礋杞藉潎琛″拰闆嗙兢鐨勪笢瑗匡紝铏界劧鏈夋柊鎵嬭创鐨勫嵄闄╋紝浣嗚繕鏄墜鐥掞紝鍐冲畾鍐欑偣涓滆タ锛屼互澶囦笉鏃朵箣闇€銆備篃甯屾湜鑳藉澶у鏈夋墍甯姪銆偮?br>
绗竴绔? 鑳屾櫙绠€浠嬄?br>瀵逛簬澶у鏁颁紒涓氬簲鐢紝閮藉笇鏈涜兘鍋氬埌7*24灏忔椂涓嶉棿鏂繍琛屻€傝淇濇寔濡傛楂樼殑鍙敤鎬у苟闈炴槗浜嬶紝姣旇緝甯歌鐨勫仛娉曟槸灏嗙郴缁熼儴缃插埌澶氬彴鏈哄櫒涓婏紝姣忓彴鏈哄櫒閮藉澶栨彁渚涘悓鏍风殑鍔熻兘锛岃繖灏辨槸闆嗙兢銆傜郴缁熷彉涓洪泦缇ゆ椂锛岄櫎浜嗚姹傜郴缁熻兘澶熸敮鎸佹按骞充几缂╁锛岃繕瑕佽В鍐充袱涓棶棰橈細聽
1锛?濡備綍鍧囪 鍦拌闂埌鎻愪緵涓氬姟鍔熻兘鐨勬満鍣ㄣ€偮?br>2锛?濡備綍淇濊瘉褰撴満鍣ㄥ嚭鐜伴棶棰樻椂锛岀敤鎴疯兘鑷姩璺宠浆鍒板彟澶栫殑鏈哄櫒锛屼笉褰卞搷浣跨敤銆?/span>聽
甯哥敤鐨勮礋杞藉潎琛℃妧鏈湁纭欢鍜岃蒋浠朵袱绉嶏紝鏈ず渚嬪父鐢ㄨ蒋浠剁殑鎶€鏈疄鐜般€傝蒋浠朵篃鏈夊緢澶氬疄鐜版妧鏈紝濡傚熀浜巃pache鐨刴od_jk浠ュ強mod_proxy绛夈€傚熀浜巑od_jk鐨勬枃绔犳湁涓嶅皯锛屾湰鏂囨紨绀轰竴涓嬬敤mod_proxy鐨勬柟寮忋€偮?br>瀹炵幇闆嗙兢鐨勫簲鐢ㄦ渶閲嶈鐨勬槸澶勭悊鐢ㄦ埛Session鐨勯棶棰橈紝涓€鑸湁涓夌绛栫暐锛毬?br>1锛?Session澶嶅埗聽
2锛?Session Sticky聽
3锛?鍩轰簬Cache鐨勯泦涓紡Session

鏈枃浣跨敤鐨勬槸Tomcat 7.0.2搴旂敤鏈嶅姟鍣紝鐢ㄧ殑鏂规硶鏄疭ession澶嶅埗銆偮?br>
绗簩绔? 閰嶇疆鐜聽
1锛?JDK1.6,璇疯嚜琛屼笅杞藉畨瑁?鎼濲ava鐨勪竴鑸兘瑁呮湁鐨勫惂锛屽搱鍝堛€偮?br>2锛?Apache 2.2.16, (released 2010-07-25),鐜板湪涓烘搴旇鏄渶鏂扮殑绋冲畾鐗堟湰锛屼笅杞藉湴鍧€: http://httpd.apache.org/download.cgi聽
3锛?Tomcat 7.0.2,鐩墠涔熸槸鏈€鏂扮殑鐗堟湰銆侻inimum Java Version1.6.涓嬭浇鍦板潃锛歨ttp://tomcat.apache.org/download-70.cgi聽
4锛?瀹夎杩囩▼鐣ヂ?br>
绗笁绔? 閮ㄧ讲鍥韭?br>
鍩轰簬mod_proxy+Apache 2.2.16+Tomcat 七鐨勮礋杞藉潎琛′笌闆嗙兢閰嶇疆


绗洓绔? Tomcat7闆嗙兢閰嶇疆聽
涓€銆?灏卞湴鍙栨潗锛屽鍒秚omcat7/webapps涓嬬殑examples,閲嶅懡鍚嶄负cluster搴旂敤,浠ュ悗灏辩敤cluster鍋氭祴璇曘€偮?br>浜屻€?璇︾粏閰嶇疆鍙傜収tomcat7 \webapps\docs\cluster-howto.html 鎴栬€卙ttp://tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html聽
涓夈€?涓轰簡鍦═omcat7涓疄鐜皊ession澶嶅埗锛屼互涓嬪繀闇€瀹屾垚锛毬?br>鈥?鎵€鏈塻ession灞炴€у繀闇€瀹炵幇 java.io.Serializable聽
鈥?Uncomment the Cluster element in server.xml銆傛妸Cluster鍏冪礌鐨勬敞閲婂幓鎺夈€傚弬鐓у洓聽
鈥?If you have defined custom cluster valves, make sure you have the ReplicationValve defined as well under the Cluster element in server.xml 銆傚弬鐓у洓聽
鈥?If your Tomcat instances are running on the same machine, make sure the tcpListenPort attribute is unique for each instance, in most cases Tomcat is smart enough to resolve this on it's own by autodetecting available ports in the range 4000-4100銆傚弬鐓у洓< Receiver>涓殑娉ㄩ噴聽
鈥?Make sure your web.xml has the <distributable/> element or set at your <Context distributable="true" /> 鍙傜収鍥浡?br>鈥?If you are using mod_jk, make sure that jvmRoute attribute is set at your Engine <Engine name="Catalina" jvmRoute="node01" > and that the jvmRoute attribute value matches your worker name in workers.properties .鐢╩od_jk鐨勬儏鍐碉紝鎴戜滑鍙互涓嶇銆偮?br>鈥?Make sure that all nodes have the same time and sync with NTP service! 褰撲娇鐢ㄥ鍙版満鍣ㄦ椂锛岃淇濊瘉涓嶅悓鏈哄櫒鏃堕棿鐨勫悓姝ャ€傚師鍥犱负tomcat session澶嶅埗鐨勪竴浜涙満鍒躲€傚叿浣撳師鍥犵湅鏂囨。銆偮?br>鈥?Make sure that your loadbalancer is configured for sticky session mode. 淇濊瘉璐熻浇鍧囪 杞欢璁剧疆涓簊ession sticky妯″紡銆偮?br>鍥涖€?璇︾粏閰嶇疆锛毬?br>1. 淇敼tomcat7_a/conf/server.xml, 鎴戜滑閲囩敤鐨勬槸榛樿鐨勯厤缃紝鍦?lt;Engine>鑺傜偣涓嬫坊鍔狅細聽

Java浠g爜聽
  1. <Cluster聽className="org.apache.catalina.ha.tcp.SimpleTcpCluster"聽聽
  2. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽channelSendOptions="8">聽聽
  3. 聽聽
  4. 聽聽聽聽聽聽聽聽聽聽<Manager聽className="org.apache.catalina.ha.session.DeltaManager"聽聽
  5. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽expireSessionsOnShutdown="false"聽聽
  6. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽notifyListenersOnReplication="true"/>聽聽
  7. 聽聽
  8. 聽聽聽聽聽聽聽聽聽聽<Channel聽className="org.apache.catalina.tribes.group.GroupChannel">聽聽
  9. 聽聽聽聽聽聽聽聽聽聽聽聽<Membership聽className="org.apache.catalina.tribes.membership.McastService"聽聽
  10. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽address="228.0.0.4"聽聽
  11. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽port="45564"聽聽
  12. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽frequency="500"聽聽
  13. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽dropTime="3000"/>聽聽
  14. 聽聽聽聽聽聽聽聽聽聽聽聽<Receiver聽className="org.apache.catalina.tribes.transport.nio.NioReceiver"聽聽
  15. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽address="auto"聽聽
  16. <!鈥攖cpListenPort濡傛灉鏄悓涓€鏈哄櫒閮ㄧ讲涓や釜tomcat7搴旂敤锛屽垯淇敼tomcat7_b涓?span style="color: #c00000;" class="number">4001锛屼互鍏嶅啿绐?聽涓嶅悓鏈哄櫒涓嬶紝涓嶇敤鏇存敼姝ら」銆傗€?gt;聽聽
  17. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽[color=red]port="4000"[/color]聽聽
  18. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽autoBind="100"聽聽
  19. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽selectorTimeout="5000"聽聽
  20. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽maxThreads="6"/>聽聽
  21. 聽聽
  22. 聽聽聽聽聽聽聽聽聽聽聽聽<Sender聽className="org.apache.catalina.tribes.transport.ReplicationTransmitter">聽聽
  23. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽<Transport聽className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>聽聽
  24. 聽聽聽聽聽聽聽聽聽聽聽聽</Sender>聽聽
  25. 聽聽聽聽聽聽聽聽聽聽聽聽<Interceptor聽className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>聽聽
  26. 聽聽聽聽聽聽聽聽聽聽聽聽<Interceptor聽className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>聽聽
  27. 聽聽聽聽聽聽聽聽聽聽</Channel>聽聽
  28. 聽聽
  29. 聽聽聽聽聽聽聽聽聽聽<Valve聽className="org.apache.catalina.ha.tcp.ReplicationValve"聽聽
  30. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽filter=""/>聽聽
  31. 聽聽聽聽聽聽聽聽聽聽<Valve聽className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>聽聽
  32. 聽聽
  33. 聽聽聽聽聽聽聽聽聽聽<Deployer聽className="org.apache.catalina.ha.deploy.FarmWarDeployer"聽聽
  34. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽tempDir="/tmp/war-temp/"聽聽
  35. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽deployDir="/tmp/war-deploy/"聽聽
  36. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽watchDir="/tmp/war-listen/"聽聽
  37. 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽watchEnabled="false"/>聽聽
  38. 聽聽
  39. 聽聽聽聽聽聽聽聽聽聽<ClusterListener聽className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>聽聽
  40. 聽聽聽聽聽聽聽聽聽聽<ClusterListener聽className="org.apache.catalina.ha.session.ClusterSessionListener"/>聽聽
  41. 聽聽聽聽聽聽聽聽</Cluster>聽聽

2. <Connector聽port="8081"聽protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> 淇敼锛屼粎涓轰簡璋冭瘯鏂逛究銆偮?br>3. tomcat7_a\webapps\cluster\WEB-INF\web.xml涓姞鍏?span style="color: red;"><distributable/>

4. <Engine name="Catalina" defaultHost="localhost"聽jvmRoute="tomcat7_a">,娣诲姞jvmRoute灞炴€э紝姝ら」涓哄悗闈pache璐熻浇鍧囪 鐢ㄥ埌銆偮?br>
浜斻€?澶嶅埗涓€浠絫omcat7_a搴旂敤,鏀瑰悕涓簍omcat7_b.鍙槸涓轰簡鍥炬柟渚匡紝瀹為檯搴旇澶嶅埗鐨勬槸鍓嶉潰鐨刢luster宸ョ▼銆傛敞鎰忎互涓嬪嚑鐐归厤缃氨ok.聽
1. 淇敼tomcat7_a/conf/server.xml 涓殑Server port灞炴€?lt;Server聽port="8006"聽shutdown="SHUTDOWN">,鍥犱负鏄悓涓€鍙版満鍣ㄤ袱涓猼omcat搴旂敤锛屾墍浠ユ敼涓€涓嬨€偮?br>2. 淇敼<connector聽port="8082"聽protocol="HTTP/1.1" onnectionTimeout="20000" edirectPort="8443" />,鍚岀悊锛屼负浜嗛伩鍏嶅悓涓€鍙版満鍣ㄧ鍙e彿鍐茬獊銆傞儴缃湪涓嶅悓鐨勬満鍣ㄦ槸涓嶇敤绠$殑銆偮?br>3. 淇敼<Engine name="Catalina" defaultHost="localhost"聽jvmRoute="tomcat7_b">锛?/span>姝ら」涓哄悗闈pache璐熻浇鍧囪 鐢ㄥ埌銆偮?br>4. 淇敼<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="auto"port="4001"聽autoBind="100" selectorTimeout="5000" maxThreads="6"/>聽
5. tomcat7_b\ebapps\cluster\WEB-INF\web.xml涓姞鍏?span style="color: red;"><distributable/>

鍒版闆嗙兢閰嶇疆瀹屾垚.聽
绗簲绔? 闆嗙兢娴嬭瘯聽
1. tomcat7_a鍜宼omcat7_b鐨刢luster宸ョ▼涓垎鍒坊鍔犳祴璇曟枃浠?testCluster.jsp聽
Java浠g爜聽
  1. <%@聽page聽contentType="text/html;聽charset=GBK"聽%>聽聽
  2. <%@聽page聽import="java.util.*"聽%>聽聽
  3. <html><head><title>Cluster聽Test</title></head>聽聽
  4. <body>聽聽
  5. <%聽聽
  6. 聽聽//HttpSession聽session聽=聽request.getSession(true);聽聽
  7. 聽聽System.out.println(session.getId());聽聽
  8. 聽聽out.println("<br>聽SESSION聽ID:"聽+聽session.getId()+"<br>");聽聽聽聽
  9. 聽聽//聽濡傛灉鏈夋柊鐨勮姹傦紝鍒欐坊鍔爏ession灞炴€?/span>聽聽
  10. 聽聽String聽name聽=聽request.getParameter("name");聽聽
  11. 聽聽if聽(name聽!=聽null聽&&聽name.length()聽>聽0)聽{聽聽
  12. 聽聽聽聽聽String聽value聽=聽request.getParameter("value");聽聽
  13. 聽聽聽聽聽session.setAttribute(name,聽value);聽聽
  14. 聽聽}聽聽聽聽
  15. 聽聽聽聽out.print("<b>Session聽List:</b>");聽聽聽聽
  16. 聽聽聽聽Enumeration<String>聽names聽=聽session.getAttributeNames();聽聽
  17. 聽聽聽聽while聽(names.hasMoreElements())聽{聽聽
  18. 聽聽聽聽聽聽聽聽String聽sname聽=聽names.nextElement();聽聽聽
  19. 聽聽聽聽聽聽聽聽String聽value聽=聽session.getAttribute(sname).toString();聽聽
  20. 聽聽聽聽聽聽聽聽out.println(聽sname聽+聽"聽=聽"聽+聽value+"<br>");聽聽
  21. 聽聽聽聽聽聽聽聽System.out.println(聽sname聽+聽"聽=聽"聽+聽value);聽聽
  22. 聽聽聽}聽聽
  23. %>聽聽
  24. 聽聽<form聽action="testCluster.jsp"聽method="post">聽聽
  25. 聽聽聽聽鍚嶇О:<input聽type=text聽size=20聽name="name">聽聽
  26. 聽聽聽聽聽<br>聽聽
  27. 聽聽聽聽鍊?<input聽type=text聽size=20聽name="value">聽聽
  28. 聽聽聽聽聽<br>聽聽
  29. 聽聽聽聽<input聽type=submit聽value="鎻愪氦">聽聽
  30. 聽聽聽</form>聽聽
  31. </body>聽聽
  32. </html>聽聽

2. 鍚姩tomcat7_a,鍚姩瀹屾瘯鍚庯紝鍚姩tomcat7_b聽
3. 杩涘叆http://localhost:8081/cluster/testCluster.jsp 瀵瑰簲tomcat7_a(8081)锛岀櫥褰曞嚑娆★紝鍙湅鍒奥?br>
鍩轰簬mod_proxy+Apache 2.2.16+Tomcat 七鐨勮礋杞藉潎琛′笌闆嗙兢閰嶇疆

4. 鍙﹀鎵撳紑涓€涓祻瑙堝櫒锛岃繘鍏ttp://localhost:8082/cluster/testCluster.jsp瀵瑰簲tomcat7_b(8082)锛岀櫥褰昻ame:tomcat_b锛寁alue:b value鍙湅鍒奥?br>
鍩轰簬mod_proxy+Apache 2.2.16+Tomcat 七鐨勮礋杞藉潎琛′笌闆嗙兢閰嶇疆


5. 鍒锋柊tomcat7_a(8081)鐩稿叧椤甸潰,鍙互鐪嬪埌浠巘omcat7_b鎻愪氦鐨勫€約ession鍚屾杩囨潵浜嗭紝璇存槑闆嗙兢鎴愬姛銆偮?br>
鍩轰簬mod_proxy+Apache 2.2.16+Tomcat 七鐨勮礋杞藉潎琛′笌闆嗙兢閰嶇疆


鍩轰簬mod_proxy+Apache 2.2.16+Tomcat 七鐨勮礋杞藉潎琛′笌闆嗙兢閰嶇疆



绗叚绔? Session闆嗙兢宸ヤ綔姝ラ聽
鍙傜収tomcat7 doc:聽
To make it easy to understand how clustering works, We are gonna take you through a series of scenarios. In the scenario we only plan to use two tomcat instances TomcatA and TomcatB. We will cover the following sequence of events:聽
1. TomcatA starts up聽
2. TomcatB starts up (Wait that TomcatA start is complete)聽
3. TomcatA receives a request, a session S1 is created.聽
4. TomcatA crashes聽
5. TomcatB receives a request for session S1聽
6. TomcatA starts up聽
7. TomcatA receives a request, invalidate is called on the session (S1)聽
8. TomcatB receives a request, for a new session (S2)聽
9. TomcatA The session S2 expires due to inactivity.聽

绗竷绔? 璐熻浇鍧囪 閰嶇疆聽
Tomcat鏈変袱绉嶈礋杞藉潎琛$殑鏂瑰紡锛毬?br>1. 浣跨敤 JK1.2.x native connector聽
2. 浣跨敤Apache HTTP Server 2.x with mod_proxy聽
鎴戜滑浣跨敤鐨勬槸mod_proxy,鍦ˋpache Http Server2.2浠ヤ笂鐗堟湰宸茬粡鑷姩甯︽湁锛毬?br>Mod_proxy supports either HTTP or AJP load balancing. 鎴戜滑閫氳繃ajp鏂瑰紡銆偮?br>
璇︾粏鏌ョ湅锛歵omcat7\webapps\docs\balancer-howto.html聽
1. 棣栧厛,鐩戝惉8000绔彛, 鍦ˋpache瀹夎鐩綍涓嬫壘鍒癱onf/httpd.conf鏂囦欢聽
绋嶅墠闈㈠姞涓娐?br>
Java浠g爜聽
  1. #聽鐩戝惉绔彛鍜岀洃鍚湴鍧€聽聽
  2. Listen聽8000聽聽

2. conf/httpd.conf,鍘绘帀浠ヤ笅鏂囨湰鍓嶇殑娉ㄩ噴绗?#)浠ヤ究璁〢pache鍦ㄥ惎鍔ㄦ椂鑷姩鍔犺浇浠g悊(proxy)妯″潡锝÷?br>
Java浠g爜聽
  1. LoadModule聽proxy_module聽modules/mod_proxy.so聽聽聽聽
  2. LoadModule聽proxy_ajp_module聽modules/mod_proxy_ajp.so聽聽聽聽
  3. LoadModule聽proxy_balancer_module聽modules/mod_proxy_balancer.so聽聽聽聽
  4. LoadModule聽proxy_connect_module聽modules/mod_proxy_connect.so聽聽聽聽
  5. LoadModule聽proxy_ftp_module聽modules/mod_proxy_ftp.so聽聽聽聽
  6. LoadModule聽proxy_http_module聽modules/mod_proxy_http.so聽聽聽


3. conf/httpd.conf鏂囦欢鏈€鍚庡姞涓?聽
Java浠g爜聽
  1. #铏氭嫙鏈洪厤缃?璐熻浇鍧囪 閰嶇疆聽聽
  2. <VirtualHost聽*:8000>聽聽
  3. 聽聽聽聽ServerAdmin聽weigbo@163.com聽聽
  4. 聽聽聽聽ServerName聽localhost聽聽
  5. 聽聽聽聽ServerAlias聽localhost聽聽
  6. 聽聽聽聽#灏忓績锛屾湁浜涘湴鏂硅鏈夌┖鏍硷紝瑕佷笉鐒朵細鍑洪敊鍝堝搱銆偮犅?/span>
  7. 聽聽聽聽ProxyPass聽/聽balancer://cluster/聽stickysession=JSESSIONID|jsessionid聽nofailover=On聽聽
  8. 聽聽聽聽ProxyPassReverse聽/聽balancer://cluster/聽聽
  9. 聽聽聽聽#ErrorLog聽"logs/error.log"聽聽
  10. 聽聽聽聽#CustomLog聽"logs/access.log"聽common聽聽
  11. </VirtualHost>聽聽聽
  12. 聽聽
  13. #The聽ProxyRequests聽directive聽should聽usually聽be聽set聽off聽when聽using聽ProxyPass.聽聽
  14. ProxyRequests聽Off聽聽
  15. <proxy聽balancer://cluster>聽聽
  16. 聽聽聽聽BalancerMember聽ajp://localhost:8009聽loadfactor=1聽route=tomcat7_a聽聽smax=5聽max=20聽ttl=120聽retry=300聽timeout=15聽聽
  17. 聽聽聽聽BalancerMember聽ajp://localhost:9009聽loadfactor=1聽route=tomcat7_b聽聽smax=5聽max=20聽ttl=120聽retry=300聽timeout=15聽聽
  18. 聽聽聽聽#聽status=+H涓洪厤缃儹澶囷紝褰撴墍鏈夋満鍣ㄩ兘over鏃讹紝鎵嶄細璇锋眰璇ユ満鍣犅?/span>
  19. 聽聽聽聽#BalancerMember聽http://192.168.1.218:8009聽status=+H聽聽
  20. 聽聽聽聽ProxySet聽lbmethod=bytraffic聽聽
  21. </proxy>聽聽
4. Tomcat7閰嶇疆(server.xml):聽
鍥犱负鏄悓涓€鏈哄櫒锛屼袱涓簲鐢紝鎵€浠ラ厤涓嶅悓鐨勭鍙o紝涓嶅悓鏈哄櫒鍒欎笉鐢ㄩ厤锛岃鍜屽墠闈㈢殑ajp瀵瑰簲涓娿€偮?br><Connector聽port="8009"聽protocol="AJP/1.3" redirectPort="8443" />聽
<Connector聽port="9009"聽protocol="AJP/1.3" redirectPort="8443" />聽

绗叓绔? 璐熻浇鍧囪 娴嬭瘯聽
Tomcat7_a鐨刢luster宸ョ▼鐨勬祴璇曟枃浠?testCluster.jsp鍔犱笂html浠g爜:聽
<b>璐熻浇鍧囪 娴嬭瘯锛氭涓猴細Tomcat7_a涓婄殑鏂囦欢锛?lt;font color=red>aaaaaaaaaaaaaaaaaa</font><b>聽

Tomcat7_b鐨刢luster宸ョ▼鐨勬祴璇曟枃浠?testCluster.jsp鍔犱笂html浠g爜聽
<b>璐熻浇鍧囪 娴嬭瘯锛氭涓猴細Tomcat7_b涓婄殑鏂囦欢锛?lt;font color=red>bbbbbbbbbbbbbbbbbb</font><b>聽

鎵撳紑娴忚鍣紝杩涘叆鍦板潃锛歨ttp://localhost:8000/cluster/testCluster.jsp聽
澶氬埛鏂板嚑娆★紝浼氱湅鍒伴〉闈㈠€间細鍦╝aaaa鍜宐bbbb闂村垏鎹紝璇存槑璐熻浇鍧囪 閰嶇疆鎴愬姛銆傚鍥撅細聽

鍩轰簬mod_proxy+Apache 2.2.16+Tomcat 七鐨勮礋杞藉潎琛′笌闆嗙兢閰嶇疆


鍩轰簬mod_proxy+Apache 2.2.16+Tomcat 七鐨勮礋杞藉潎琛′笌闆嗙兢閰嶇疆



绗節绔? Mod_proxy璐熻浇鍧囪 绠楁硶聽
鐩墠mod_proxy鏈?绉嶈礋杞藉潎琛$畻娉曪細聽
1. Request Counting(鎴戠寽鏄疪ound-robin), lbmethod=byrequests聽
2. Weighted Traffic Counting(杩欎釜鏄寜鏉冮噸锛屾渚嬩篃鏄敤姝ょ畻娉?, lbmethod=bytraffic聽
3. Pending Request Counting(浠巃pche鏂囨。鏉ョ湅锛屽簲璇ユ槸鎸夎礋杞介噺锛屼篃灏辨槸寰€璐熻浇灏戠殑娲惧彂鏂拌姹?. lbmethod=bybusyness聽
瀹冧滑閫氳繃lbmethod鍊艰缃€偮?br>绗崄绔? 鍙傝€冩枃妗o細聽
Tomcat 7 doc鏂囨。聽
http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html聽
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html聽

绗崄涓€绔? 琛ュ厖鍐呭锛氳礋杞藉潎琛$鐞嗗櫒聽
璐熻浇鍧囪 绠$悊鍣ㄥ彲浠ュ姩鎬佹洿鏂拌礋杞藉潎琛$殑搴旂敤锛屼綘鍙互鐢ㄧ鐞嗗櫒鏇存敼璐熻浇鍥犲瓙鎴栬€呯壒瀹氱殑搴旂敤锛岃繕鍙互鎶婂簲鐢ㄨ涓簅ff妯″紡銆偮?br>涓轰簡浣跨敤balancer management, mod_status鍜宮od_proxy_balancer 蹇呴渶瑕佸姞杞藉埌apache.聽
璁剧疆:聽
#姝ら」涓簃od_proxy_balancer绠$悊鍣ㄩ渶瑕伮?br>LoadModule status_module modules/mod_status.so聽

鍦ㄨ礋杞藉潎琛¢」鍓嶅姞涓婏細聽
#mod_balancer绠$悊搴旂敤聽
<Location /balancer-manager>聽聽聽
聽聽聽聽 SetHandler balancer-manager聽
聽聽聽聽 Order Allow,Deny聽
聽聽聽聽 Allow from all聽
</Location>聽

鍙互閫氳繃浠ヤ笅鍦板潃璁块棶锛歨ttp://localhost:8000/balancer-manager聽

鍩轰簬mod_proxy+Apache 2.2.16+Tomcat 七鐨勮礋杞藉潎琛′笌闆嗙兢閰嶇疆


闄勪欢涓槸涓€浜涚浉鍏崇殑閰嶇疆鏂囦欢锛屽ぇ瀹跺彲浠ュ弬鑰冿細聽

  • cluster_loadbalance.rar聽(15.7 KB)
  • 涓嬭浇娆℃暟: 1206
  • 鏌ョ湅鍥剧墖闄勪欢

文章评论