欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

tomcat的集群配置

系統 2523 0

配置環境需要:1.Apache服務器,下載地址: http://httpd.apache.org/download.cgi#apache22

?2.tomcat6.0或者tomcat7.0,( 集群中 tomcat 不能既有 tomcat6 又有 tomcat7 ,否則雖能夠負載均衡,但不能進行 session 復制, 下載地址: http://tomcat.apache.org/

?3.jk是tomcat提供給http服務器的插件mod_jk-1.2.31-httpd-2.2.3.so? ? ? 下載地址: http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.31/

?

修改Apache配置

1、修改httpd.conf

我的Apache安裝在D:\Program Files\Apache Software Foundation\Apache2.2,找到conf目錄下的httpd.conf,在文件的最后一行添加

include "D:\Program Files\Apache Software Foundation\Apache2.2\conf\mod_jk.conf"

2、新建mod_jk.conf文件,內容如下:

#加載mod_jk Module
LoadModule jk_module modules/mod_jk-1.2.31-httpd-2.2.3.so
#指定workers.properties文件路徑
JkWorkersFile conf/workers.properties
#指定那些請求交給tomcat處理,"controller"為在workers.propertise里指定的負載分配控制器名
JkMount /*.jsp controller

3、將下載的JK插件mod_jk-1.2.31-httpd-2.2.3.so復制到Apache安裝目錄的modules目錄下。

4、新建并編輯workers.properties文件,內容如下:

worker.list = controller,tomcat1,tomcat2 ?#server 列表?
#========tomcat1======== ?
worker.tomcat1.port=11009 ? ?#ajp13 端口號,在tomcat下server.xml配置,默認8009
worker.tomcat1.host=localhost ? #tomcat的主機地址,如不為本機,請填寫ip地址?
worker.tomcat1.type=ajp13 ?
worker.tomcat1.lbfactor = 1 ? #server的加權比重,值越高,分得的請求越多
#========tomcat2======== ?
worker.tomcat2.port=12009 ? ?#ajp13 端口號,在tomcat下server.xml配置,默認8009?
worker.tomcat2.host=localhost ? #tomcat的主機地址,如不為本機,請填寫ip地址?
worker.tomcat2.type=ajp13?
worker.tomcat2.lbfactor = 1 ?#server的加權比重,值越高,分得的請求越多?
#========tomcat3======== ?
worker.tomcat3.port=8009 ? ?#ajp13 端口號,在tomcat下server.xml配置,默認8009?
worker.tomcat3.host=localhost ? #tomcat的主機地址,如不為本機,請填寫ip地址?
worker.tomcat3.type=ajp13?
worker.tomcat3.lbfactor = 1 ?#server的加權比重,值越高,分得的請求越多
#========controller,負載均衡控制器========?
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2,tomcat3
worker.controller.sticky_session=false(false指的是實現session復制)

這里可以配置任意多個Tomcat,此處配置了3個Tomat服務器,2個本地,1個遠程,所以為了它們都能夠順利啟動起來,本地的服務器端口都是不同的,如果Tomcat不再同一機器上,沒必要改端口的。下面是tomcat1的server.xml的配置

<?xml version='1.0' encoding='utf-8'?>
<!--
? 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 "License"); you may not use this file except in compliance with
? the License. ?You may obtain a copy of the License at
? ? ? http://www.apache.org/licenses/LICENSE-2.0
? Unless required by applicable law or agreed to in writing, software
? distributed 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 and
? limitations under the License.
-->
<!-- Note: ?A "Server" is not itself a "Container", so you may not
? ? ?define subcomponents such as "Valves" at this level.
? ? ?Documentation at /docs/config/server.html
?-->
<Server port=" 8001 " shutdown="SHUTDOWN">
? <!--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" />
? <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
? <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
? <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
? <!-- Global JNDI resources
? ? ? ?Documentation at /docs/jndi-resources-howto.html
? -->
? <GlobalNamingResources>
? ? <!-- Editable user database that can also be used by
? ? ? ? ?UserDatabaseRealm 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 share
? ? ? ?a 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 received
? ? ? ? ?and responses are returned. Documentation at :
? ? ? ? ?Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
? ? ? ? ?Java AJP ?Connector: /docs/config/ajp.html
? ? ? ? ?APR (HTTP/AJP) Connector: /docs/apr.html
? ? ? ? ?Define a non-SSL HTTP/1.1 Connector on port 8080
? ? -->
? ? <Connector port=" 8081 " protocol="HTTP/1.1"?
? ? ? ? ? ? ? ?connectionTimeout="20000"?
? ? ? ? ? ? ? ?redirectPort="8443" />
? ? <!-- 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 8443
? ? ? ? ?This connector uses the JSSE configuration, when using APR, the?
? ? ? ? ?connector should be using the OpenSSL style configuration
? ? ? ? ?described in the APR documentation -->
? ? <!--
? ? <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
? ? ? ? ? ? ? ?maxThreads="150" scheme="https" secure="true"
? ? ? ? ? ? ? ?clientAuth="false" sslProtocol="TLS" />
? ? -->
? ? <!-- Define an AJP 1.3 Connector on port 8009 -->
? ? <Connector port=" 11009 " 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"/>??
<!-- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" ?
? ? ? ? ? ? ? ? ?channelSendOptions="8"> ?-->
? ? ? ? ? <!-- ? ?? ? ? ? ? ??
? ? ? ? ? <Manager className="org.apache.catalina.ha.session.BackupManager" ?
? ? ? ? ? ? ? ? ? ? expireSessionsOnShutdown="false" ?
? ? ? ? ? ? ? ? ? ? notifyListenersOnReplication="true" ?
? ? ? ? ? ? ? ? ? ? mapSendOptions="8"/> --> ?
? ? ? ? ? ??
? ? ? ? ?<!-- <Manager className="org.apache.catalina.ha.session.DeltaManager" ?
? ? ? ? ? ? ? ? ? ?expireSessionsOnShutdown="false" ?
? ? ? ? ? ? ? ? ? ?notifyListenersOnReplication="true"/> ?
??
? ? ? ? ? <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="4000" ?
? ? ? ? ? ? ? ? ? ? ? autoBind="100" ?
? ? ? ? ? ? ? ? ? ? ? selectorTimeout="5000" ?
? ? ? ? ? ? ? ? ? ? ? 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=""/> ?
? ? ? ? ? <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/> ?
??
? ? ? ? ? <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.JvmRouteSessionIDBinderListener"/> ?
? ? ? ? ? <ClusterListener className="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.apache.catalina.valves.RequestDumperValve"/>
? ? ? -->
? ? ? <!-- 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"/>
? ? ? <!-- Define the default virtual host
? ? ? ? ? ?Note: 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 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 -->
? ? ? ? <!--
? ? ? ? <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" ?
? ? ? ? ? ? ? ?prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
? ? ? ? -->
? ? ? </Host>
? ? </Engine>
? </Service>
</Server>

另外兩個tomcat的server.xml的配置和上面類似,只需把紅色的端口改一下即可。

?

注意: AJP13 connector port jvmRoute 名稱和 workers.properties 中配置對應。

?


測試

?

建立測試項目

建立test項目,把這個項目分別部署到三個tomcat服務器下面,同時需要在項目的WEB-INF文件夾下的web.xml中添加<distributable/>這個標簽

建立test2.jsp,內容如下:

?

    <%@ 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() + " : " + request.getLocalPort()+"<br>");%>

<%

  out.println("<br> ID " + session.getId()+"<br>");

  // 如果有新的 Session 屬性設置

  String dataName = request.getParameter("dataName");

  if (dataName != null && dataName.length() > 0) {

     String dataValue = request.getParameter("dataValue");

     session.setAttribute(dataName, dataValue);

  }

  out.println("<b>Session 列表</b><br>");

  System.out.println("============================");

  Enumeration e = session.getAttributeNames();

  while (e.hasMoreElements()) {

     String name = (String)e.nextElement();

     String value = session.getAttribute(name).toString();

     out.println( name + " = " + value+"<br>");

         System.out.println( name + " = " + value);

   }

%>

  <form action="test2.jsp" method="POST">

    名稱:<input type=text size=20 name="dataName">

     <br>

    值:<input type=text size=20 name="dataValue">

     <br>

    <input type=submit>

   </form>

</body>

</html>
  

?

Session測試

將項目部署到3個服務器之后,然后分別啟動Apache和3個Tocmat服務器,這些Tomcat啟動順序隨意,然后打開 http://localhost/test/test2.jsp

按F5每刷新一次頁面,session的ID都是一樣的說明實現了session的復制,這樣就大功告成了!


?

tomcat的集群配置


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 欧美另类色图 | 狠狠色噜噜狠狠狠狠米奇7777 | 天堂在线免费视频 | 另类亚洲视频 | 欧美日韩中文字幕在线观看 | 欧美一级毛片欧美毛片视频 | 看一级毛片国产一级毛片 | 美女久久久 | 亚洲天堂影院 | 2018天天干夜夜操 | 久久免费99精品久久久久久 | 亚洲免费人成在线视频观看 | 欧美色性 | 天天草天天干 | 黑人巨大精品 | 日韩亚洲欧美在线爱色 | 天天综合网站 | 五月天婷婷缴情五月免费观看 | 成人欧美视频在线观看 | 午夜久草| 欧美日韩后 | 热久久免费视频 | 亚洲男人的天堂网站 | 亚洲久久一区 | 国产精品69人妻无码久久久 | 久久久久国产视频 | 看免费的毛片 | 91在线| 2021年无线乱码播放高清完整 | www香蕉视频 | 亚洲中午字幕 | 免费一级毛片不卡不收费 | 亚洲福利在线观看 | 日韩av中文 | 日本在线你懂的 | 午夜日韩| 午夜精品视频在线看 | 色综合网站在线 | 精品视频一区二区观看 | 欧美一级欧美三级在线观看 | 欧美亚洲一区二区三区 |