鍩轰簬mod_proxy+Apache 2.2.16+Tomcat 七鐨勮礋杞藉潎琛′笌闆嗙兢閰嶇疆
聽
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>
绗洓绔? 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>鑺傜偣涓嬫坊鍔狅細聽
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聽
2. 鍚姩tomcat7_a,鍚姩瀹屾瘯鍚庯紝鍚姩tomcat7_b聽
3. 杩涘叆http://localhost:8081/cluster/testCluster.jsp 瀵瑰簲tomcat7_a(8081)锛岀櫥褰曞嚑娆★紝鍙湅鍒奥?br>
聽
4. 鍙﹀鎵撳紑涓€涓祻瑙堝櫒锛岃繘鍏ttp://localhost:8082/cluster/testCluster.jsp瀵瑰簲tomcat7_b(8082)锛岀櫥褰昻ame:tomcat_b锛寁alue:b value鍙湅鍒奥?br>
聽
5. 鍒锋柊tomcat7_a(8081)鐩稿叧椤甸潰,鍙互鐪嬪埌浠巘omcat7_b鎻愪氦鐨勫€約ession鍚屾杩囨潵浜嗭紝璇存槑闆嗙兢鎴愬姛銆偮?br>
聽
聽
绗叚绔? 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>
2. conf/httpd.conf,鍘绘帀浠ヤ笅鏂囨湰鍓嶇殑娉ㄩ噴绗?#)浠ヤ究璁〢pache鍦ㄥ惎鍔ㄦ椂鑷姩鍔犺浇浠g悊(proxy)妯″潡锝÷?br>
3. conf/httpd.conf鏂囦欢鏈€鍚庡姞涓?聽
鍥犱负鏄悓涓€鏈哄櫒锛屼袱涓簲鐢紝鎵€浠ラ厤涓嶅悓鐨勭鍙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璐熻浇鍧囪 绠楁硶聽
鐩墠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聽
闄勪欢涓槸涓€浜涚浉鍏崇殑閰嶇疆鏂囦欢锛屽ぇ瀹跺彲浠ュ弬鑰冿細聽
聽
- 1Apache+PHP+MYSQL的wampmysqld服务启动不了,该如何解决
- 2windows下Apache ant装配
- 3apache几种工作形式对比
- 4apache poi读取excel(03版本事前)
- 5apache 在 加载openssl 模块时出现 “/usr/local/ssl/lib/libssl.a: could not read symbols: Bad value”异常解决方案
- 6The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path 有关问题的解决
- 7Apache Thrift with Java Quickstart(thrift入门及Java范例)
- 8The APR based Apache Tomcat Native library which allows .java.library.错误
- 9apache服务器访问日志access.log设立
- 10怎么在Ubuntu上安装Apache,MySQL,PHP,Nginx,HAProxy,以及怎么在docker上安装LAMP