標籤:with proc 機器 1.3 ajp class webapps auto request
垂直負載就是同一個機器中的不同伺服器之間的負載。跟水平負載(ip不一樣的伺服器之間的負載)的最大區別就是要修改tomcat的連接埠號碼,避免引起衝突。
還要注意apache中workers.properties的配置(worker.controller.sticky_session=false),這個一定要取消session的粘性,不然會一直發到同一個伺服器中。
主要的修改點為
1.修改Tomcat 的ajp連接埠號碼,避免引起衝突
2.workers.properties的配置,worker.controller.sticky_session=false,取消粘性session
3.開啟tomcat的cluster標籤,使其支援叢集,在開啟一個Tomcat之後,開啟另一個tomcat下,如果出現以下的輸出,則表示叢集加入成功:
資訊: Replication member added:org.apache.catalina.tribes.membership.MemberImpl[tcp://{169, 254, 81, 38}:4001,{169, 254, 81, 38},4001, alive=1029, securePort=-1, UDP Port=-1, id={44 -83 62 97 -76 55 65 79 -85 47 35 -124 127 75 26 26 }, payload={}, command={}, domain={}, ]
4.開啟apache,測試叢集,不同的tomcat節點下sessionId是一樣的表示叢集成功:
以下為worker.properties設定檔:
#下面是Tomcat執行個體列表,一個apache帶一個或多個tomcatworker.list=controller,tomcat1,tomcat2#Tomcatbbs執行個體配置worker.tomcat1.host=127.0.0.1worker.tomcat1.port=8009 #ajp13 連接埠號碼,在tomcat下server.xml配置,預設8009 worker.tomcat1.type=ajp13worker.tomcat1.lbfactor = 100 #server的加權比重,值越高,分得的請求越多#Tomcatwap執行個體配置worker.tomcat2.host=127.0.0.1worker.tomcat2.port=9009worker.tomcat2.type=ajp13#server的加權比重,值越高,分得的請求越多worker.tomcat2.lbfactor = 100 #========controller,負載平衡控制器========worker.controller.type=lb#指定分擔請求的tomcatworker.controller.balanced_workers=tomcat1,tomcat2 #設定用於負載平衡的server的session可否共用 1:共用worker.controller.sticky_session=false
tomcat的server.xml的主要配置:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <!-- An Engine represents the entry point (within Catalina) 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 AJP ie : <Engine name="Catalina" 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) /docs/config/cluster.html (reference documentation) --> <!-- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> --> <!-- Use the LockOutRealm to prevent attempts to guess user passwords via a brute-force attack --> <Realm className="org.apache.catalina.realm.LockOutRealm"> <!-- This Realm uses the UserDatabase configured in the global JNDI resources under the key "UserDatabase". Any edits that are performed against this UserDatabase are immediately available 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 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 Note: 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>
另外一個tomcat的配置:
<!-- 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) 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 AJP ie : <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1"> --> <Engine defaultHost="localhost" name="Catalina" jvmRoute="tomcat2"> <!--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"/> <!-- Use the LockOutRealm to prevent attempts to guess user passwords via a brute-force attack --> <Realm className="org.apache.catalina.realm.LockOutRealm"> <!-- This Realm uses the UserDatabase configured in the global JNDI resources under the key "UserDatabase". Any edits that are performed against this UserDatabase are immediately available for use by the Realm. --> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true"> <!-- SingleSignOn valve, share authentication 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 Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/> <Context docBase="TestCluster" path="/TestCluster" reloadable="true" source="org.eclipse.jst.jee.server:TestCluster"/></Host> </Engine>
apache server和tomcat叢集配置二:垂直負載