為什么80%的碼農都做不了架構師?>>> ??
反正每次來做一個不熟悉的東西,就是各種的search ,前一次去做過一個apache的東西,各種蛋疼,各種不能用。好多的東西也是比較舊了的咯。
這次結合前輩的各種東借西拿,總算是成功了。
如果有些不明白,建議先看下一篇,,因為你的打開方式有些不對。
環境: win7 sp1.?
? ? ? ? ? ? jdk1.7?
? ? ? ? ? ? httpd2.4x64?
? ? ? ? ? ? tomcat7.59
我們這里是使用AJP模式來進行集群
sp 0: 首先是安裝apache
修改httpd.conf中的一些路徑,設置各種路徑為當前你放置apache-httpd的路徑
ServerRoot?"D:\apache24-tct7\Apache24"
//.....省略n多路徑配置
sp 1. 配置一下模塊打開
LoadModule?proxy_module?modules/mod_proxy.so
LoadModule?proxy_ajp_module?modules/mod_proxy_ajp.so
LoadModule?proxy_balancer_module?modules/mod_proxy_balancer.so
LoadModule?proxy_connect_module?modules/mod_proxy_connect.so
LoadModule?proxy_ftp_module?modules/mod_proxy_ftp.so
LoadModule?proxy_http_module?modules/mod_proxy_http.so
LoadModule?rewrite_module?modules/mod_rewrite.so
LoadModule?slotmem_shm_module?modules/mod_slotmem_shm.soLoadModule?speling_module?modules/mod_speling.soLoadModule?ssl_module?modules/mod_ssl.so
#可能還需要這個
LoadModule?lbmethod_byrequests_module?modules/mod_lbmethod_byrequests.so
LoadModule?proxy_html_module?modules/mod_proxy_html.so
1.1 配置反向代理
ProxyRequests?Off
<proxy?balancer://cluster>BalancerMember?ajp://127.0.0.1:9001?loadfactor=1?route=jvm1BalancerMember?ajp://127.0.0.1:9002?loadfactor=1?route=jvm2BalancerMember?ajp://127.0.0.1:9003?loadfactor=1?route=jvm3
</proxy>
sp 2. 配置tomcat
2.1改 SHUTDOWN 端口
? ??#同一服務器中必須不一樣,因為可能沖突
<Server?port="9006"?shutdown="SHUTDOWN">
2.2改http port?redirectPort?
? ??#同一服務器中必須不一樣,因為可能沖突
<Connector?port="8081"?protocol="HTTP/1.1"?executor="tomcatThreadPool"connectionTimeout="20000"redirectPort="9441"?/>
2.3 改ajp port?redirectPort
? ??#同一服務器中必須不一樣,因為可能沖突
<Connector?port="9001"?protocol="AJP/1.3"?redirectPort="8441"?/>
2.4 改 Engine 加上 jvmRoute 需要跟httpd.conf中保持一致
<Engine?name="Catalina"?defaultHost="localhost"?jvmRoute="jvm1">
2.5 加上Cluster? 具體如下
? ? #其中,Receiver ?port="5001" ? 同一服務器下,不能一樣
<Cluster?className="org.apache.catalina.ha.tcp.SimpleTcpCluster"?channelSendOptions="6"><Manager?className="org.apache.catalina.ha.session.BackupManager"?expireSessionsOnShutdown="false"?notifyListenersOnReplication="true"?mapSendOptions="6"?/><Channel?className="org.apache.catalina.tribes.group.GroupChannel"><Membership?className="org.apache.catalina.tribes.membership.McastService"?address="228.0.0.4"?port="45564"?frequency="500"?dropTime="3000"?/><Receiver?className="org.apache.catalina.tribes.transport.nio.NioReceiver"?address="auto"?port="5001"?selectorTimeout="100"?maxThreads="6"?/><Sender?className="org.apache.catalina.tribes.transport.ReplicationTransmitter"><Transport?className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"?/></Sender><Interceptor?className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"?/><Interceptor?className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"?/><Interceptor?className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"?/></Channel><Valve?className="org.apache.catalina.ha.tcp.ReplicationValve"?filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"?/><Deployer?className="org.apache.catalina.ha.deploy.FarmWarDeployer"?tempDir="/tmp/war-temp/"?deployDir="/tmp/war-deploy/"?watchDir="/tmp/war-listen/"?watchEnabled="false"?/><ClusterListener?className="org.apache.catalina.ha.session.ClusterSessionListener"?/></Cluster>
sp 3. 改項目web.xml
在其中添加:
<distributable?/>
節點
放一個完整一點的tomcat的server.xml
<?xml?version='1.0'?encoding='utf-8'?>
<!--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");?you?may?not?use?this?file?except?in?compliance?withthe?License.??You?may?obtain?a?copy?of?the?License?athttp://www.apache.org/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?WARRANTIES?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"?at?this?level.Documentation?at?/docs/config/server.html-->
<Server?port="9006"?shutdown="SHUTDOWN"><Listener?className="org.apache.catalina.startup.VersionLoggerListener"?/><!--?Security?listener.?Documentation?at?/docs/config/listeners.html<Listener?className="org.apache.catalina.security.SecurityListener"?/>--><!--APR?library?loader.?Documentation?at?/docs/apr.html?--><Listener?className="org.apache.catalina.core.AprLifecycleListener"?SSLEngine="on"?/><!--Initialize?Jasper?prior?to?webapps?are?loaded.?Documentation?at?/docs/jasper-howto.html?--><Listener?className="org.apache.catalina.core.JasperListener"?/><!--?Prevent?memory?leaks?due?to?use?of?particular?java/javax?APIs--><Listener?className="org.apache.catalina.core.JreMemoryLeakPreventionListener"?/><Listener?className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"?/><Listener?className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"?/><!--?Global?JNDI?resourcesDocumentation?at?/docs/jndi-resources-howto.html--><GlobalNamingResources><!--?Editable?user?database?that?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.MemoryUserDatabaseFactory"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?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="tomcatThreadPool"?namePrefix="catalina-exec-"maxThreads="150"?minSpareThreads="4"/>--><!--?A?"Connector"?represents?an?endpoint?by?which?requests?are?receivedand?responses?are?returned.?Documentation?at?:Java?HTTP?Connector:?/docs/config/http.html?(blocking?&?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="8081"?protocol="HTTP/1.1"?executor="tomcatThreadPool"connectionTimeout="20000"redirectPort="9441"?/><!--?A?"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?uses?the?BIO?implementation?that?requires?the?JSSEstyle?configuration.?When?using?the?APR/native?implementation,?theOpenSSL?style?configuration?is?required?as?described?in?the?APR/nativedocumentation?--><!--<Connector?port="8443"?protocol="org.apache.coyote.http11.Http11Protocol"maxThreads="150"?SSLEnabled="true"?scheme="https"?secure="true"clientAuth="false"?sslProtocol="TLS"?/>--><!--?Define?an?AJP?1.3?Connector?on?port?8009?--><Connector?port="9001"?protocol="AJP/1.3"?redirectPort="8441"?/><!--?An?Engine?represents?the?entry?point?(within?Catalina)?that?processesevery?request.??The?Engine?implementation?for?Tomcat?stand?aloneanalyzes?the?HTTP?headers?included?with?the?request,?and?passes?themon?to?the?appropriate?Host?(virtual?host).Documentation?at?/docs/config/engine.html?--><!--?You?should?set?jvmRoute?to?support?load-balancing?via?AJP?ie?:<Engine?name="Catalina"?defaultHost="localhost"?jvmRoute="jvm1"><Engine?name="Catalina"?defaultHost="localhost">--><Engine?name="Catalina"?defaultHost="localhost"?jvmRoute="jvm1"><!--For?clustering,?please?take?a?look?at?documentation?at:/docs/cluster-howto.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?className="org.apache.catalina.ha.session.BackupManager"?expireSessionsOnShutdown="false"?notifyListenersOnReplication="true"?mapSendOptions="6"?/><Channel?className="org.apache.catalina.tribes.group.GroupChannel"><Membership?className="org.apache.catalina.tribes.membership.McastService"?address="228.0.0.4"?port="45564"?frequency="500"?dropTime="3000"?/><Receiver?className="org.apache.catalina.tribes.transport.nio.NioReceiver"?address="auto"?port="5001"?selectorTimeout="100"?maxThreads="6"?/><Sender?className="org.apache.catalina.tribes.transport.ReplicationTransmitter"><Transport?className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"?/></Sender><Interceptor?className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"?/><Interceptor?className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"?/><Interceptor?className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"?/></Channel><Valve?className="org.apache.catalina.ha.tcp.ReplicationValve"?filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"?/><Deployer?className="org.apache.catalina.ha.deploy.FarmWarDeployer"?tempDir="/tmp/war-temp/"?deployDir="/tmp/war-deploy/"?watchDir="/tmp/war-listen/"?watchEnabled="false"?/><ClusterListener?className="org.apache.catalina.ha.session.ClusterSessionListener"?/></Cluster><!--?Use?the?LockOutRealm?to?prevent?attempts?to?guess?user?passwordsvia?a?brute-force?attack?--><Realm?className="org.apache.catalina.realm.LockOutRealm"><!--?This?Realm?uses?the?UserDatabase?configured?in?the?global?JNDIresources?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"/></Realm><Host?name="localhost"??appBase="webapps"unpackWARs="true"?autoDeploy="true"><!--?SingleSignOn?valve,?share?authentication?between?web?applicationsDocumentation?at:?/docs/config/valve.html?--><!--<Valve?className="org.apache.catalina.authenticator.SingleSignOn"?/>--><!--?Access?log?processes?all?example.Documentation?at:?/docs/config/valve.htmlNote:?The?pattern?used?is?equivalent?to?using?pattern="common"?--><Valve?className="org.apache.catalina.valves.AccessLogValve"?directory="logs"prefix="localhost_access_log."?suffix=".txt"pattern="%h?%l?%u?%t?"%r"?%s?%b"?/></Host></Engine></Service>
</Server>
具體根據需求的做法,請參考tomcat的文檔
http://http://tool.oschina.net/apidocs/apidoc?api=tomcat-7.0-doc
apache2.4 x64win 下載地址:
http://www.apachelounge.com/download/
其他的,應該不用說了吧
測試就是寫個jsp,打印下各tomcat下的項目中的session信息,以及是哪個tomcat下面的
jvm3?ID?3C5555DBBBE06EEC67B6F9508CAB0520.jvm3
Session?列表a?=?123
轉載于:https://my.oschina.net/rwrwd7/blog/406471
總結
以上是生活随笔為你收集整理的win 下 apache2.4 +tomcat7 集群的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。