apache tomcat jk整合羣集負載均衡

 本文是接上面文章所做的tomcat羣集,以及session的複製

 環境:centos5.4  apache2.2  tomcat6.0 jk1.3

 目的:單機上2個tomcat做到負載均衡並且session在多個tomcat之間複製

1 修改server.xml配置文件(直接貼我自己的)

  1. tomcat1的配置文件
  2.  
  3. <?xml version='1.0' encoding='utf-8'?> 
  4. <!-- 
  5.   Licensed to the Apache Software Foundation (ASF) under one or more 
  6.   contributor license agreements.  See the NOTICE file distributed with 
  7.   this work for additional information regarding copyright ownership. 
  8.   The ASF licenses this file to You under the Apache License, Version 2.0 
  9.   (the "License"); you may not use this file except in compliance with 
  10.   the License.  You may obtain a copy of the License at 
  11.  
  12.       http://www.apache.org/licenses/LICENSE-2.0 
  13.  
  14.   Unless required by applicable law or agreed to in writing, software 
  15.   distributed under the License is distributed on an "AS IS" BASIS, 
  16.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  17.   See the License for the specific language governing permissions and 
  18.   limitations under the License. 
  19. --> 
  20. <!-- Note:  A "Server" is not itself a "Container", so you may not 
  21.      define subcomponents such as "Valves" at this level. 
  22.      Documentation at /docs/config/server.html 
  23.  --> 
  24. <Server port="8005" shutdown="SHUTDOWN"
  25.  
  26.   <!--APR library loader. Documentation at /docs/apr.html --> 
  27.   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 
  28.   <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html --> 
  29.   <Listener className="org.apache.catalina.core.JasperListener" /> 
  30.   <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html --> 
  31.   <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" /> 
  32.   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 
  33.  
  34.   <!-- Global JNDI resources 
  35.        Documentation at /docs/jndi-resources-howto.html 
  36.   --> 
  37.   <GlobalNamingResources> 
  38.     <!-- Editable user database that can also be used by 
  39.          UserDatabaseRealm to authenticate users 
  40.     --> 
  41.     <Resource name="UserDatabase" auth="Container" 
  42.               type="org.apache.catalina.UserDatabase" 
  43.               description="User database that can be updated and saved" 
  44.               factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 
  45.               pathname="conf/tomcat-users.xml" /> 
  46.   </GlobalNamingResources> 
  47.  
  48.   <!-- A "Service" is a collection of one or more "Connectors" that share 
  49.        a single "Container" Note:  A "Service" is not itself a "Container",  
  50.        so you may not define subcomponents such as "Valves" at this level. 
  51.        Documentation at /docs/config/service.html 
  52.    --> 
  53.   <Service name="Catalina"
  54.    
  55.     <!--The connectors can use a shared executor, you can define one or more named thread pools--> 
  56.     <!-- 
  57.     <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"  
  58.         maxThreads="150" minSpareThreads="4"/> 
  59.     --> 
  60.      
  61.      
  62.     <!-- A "Connector" represents an endpoint by which requests are received 
  63.          and responses are returned. Documentation at : 
  64.          Java HTTP Connector: /docs/config/http.html (blocking & non-blocking) 
  65.          Java AJP  Connector: /docs/config/ajp.html 
  66.          APR (HTTP/AJP) Connector: /docs/apr.html 
  67.          Define a non-SSL HTTP/1.1 Connector on port 8080 
  68.     --> 
  69.     <Connector port="8080" protocol="HTTP/1.1"  
  70.                connectionTimeout="20000"  
  71.                redirectPort="8443" /> 
  72.     <!-- A "Connector" using the shared thread pool--> 
  73.     <!-- 
  74.     <Connector executor="tomcatThreadPool" 
  75.                port="8080" protocol="HTTP/1.1"  
  76.                connectionTimeout="20000"  
  77.                redirectPort="8443" /> 
  78.     -->            
  79.     <!-- Define a SSL HTTP/1.1 Connector on port 8443 
  80.          This connector uses the JSSE configuration, when using APR, the  
  81.          connector should be using the OpenSSL style configuration 
  82.          described in the APR documentation --> 
  83.     <!-- 
  84.     <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" 
  85.                maxThreads="150" scheme="https" secure="true" 
  86.                clientAuth="false" sslProtocol="TLS" /> 
  87.     --> 
  88.  
  89.     <!-- Define an AJP 1.3 Connector on port 8009 --> 
  90.     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 
  91.  
  92.  
  93.     <!-- An Engine represents the entry point (within Catalina) that processes 
  94.          every request.  The Engine implementation for Tomcat stand alone 
  95.          analyzes the HTTP headers included with the request, and passes them 
  96.          on to the appropriate Host (virtual host). 
  97.          Documentation at /docs/config/engine.html --> 
  98.  
  99.     <!-- You should set jvmRoute to support load-balancing via AJP ie : 
  100.     <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">          
  101.     -->  
  102.     <Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1"
  103.  
  104.       <!--For clustering, please take a look at documentation at: 
  105.           /docs/cluster-howto.html  (simple how to) 
  106.           /docs/config/cluster.html (reference documentation) --> 
  107.       <!-- 
  108.       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> 
  109.       -->         
  110.       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"  channelSendOptions="8">      
  111.          
  112.        <Manager className="org.apache.catalina.ha.session.DeltaManager"     
  113.                 expireSessionsOnShutdown="false"     
  114.                 notifyListenersOnReplication="true"/>      
  115.    
  116.        <Channel className="org.apache.catalina.tribes.group.GroupChannel">      
  117.          <Membership className="org.apache.catalina.tribes.membership.McastService"     
  118.                      address="228.0.0.4"     
  119.                      port="45564"     
  120.                      frequency="500"     
  121.                      dropTime="3000"/>      
  122.          <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"     
  123.                     address="auto"   
  124.                    port="4001"     
  125.                    autoBind="100"     
  126.                    selectorTimeout="5000"     
  127.                    maxThreads="6"/>      
  128.          <!-- timeout="60000"-->      
  129.          <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">      
  130.            <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />      
  131.          </Sender>      
  132.          <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>      
  133.          <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>      
  134.          <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>      
  135.        </Channel>      
  136.    
  137.        <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"     
  138.               filter=""/>      
  139.        <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>      
  140.    
  141.        <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>      
  142.        <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>      
  143.      </Cluster>   
  144.       <!-- The request dumper valve dumps useful debugging information about 
  145.            the request and response data received and sent by Tomcat. 
  146.            Documentation at: /docs/config/valve.html --> 
  147.       <!-- 
  148.       <Valve className="org.apache.catalina.valves.RequestDumperValve"/> 
  149.       --> 
  150.  
  151.       <!-- This Realm uses the UserDatabase configured in the global JNDI 
  152.            resources under the key "UserDatabase".  Any edits 
  153.            that are performed against this UserDatabase are immediately 
  154.            available for use by the Realm.  --> 
  155.       <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
  156.              resourceName="UserDatabase"/> 
  157.  
  158.       <!-- Define the default virtual host 
  159.            Note: XML Schema validation will not work with Xerces 2.2. 
  160.        --> 
  161.       <Host name="localhost"  appBase="webapps" 
  162.             unpackWARs="true" autoDeploy="true" 
  163.             xmlValidation="false" xmlNamespaceAware="false"
  164.  
  165. <Context path="" docBase="/opt/webapps/test1" debug="0" reloadable="true" crossContext="true"/> 
  166.  
  167.         <!-- SingleSignOn valve, share authentication between web applications 
  168.              Documentation at: /docs/config/valve.html --> 
  169.         <!-- 
  170.         <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> 
  171.         --> 
  172.  
  173.         <!-- Access log processes all example. 
  174.              Documentation at: /docs/config/valve.html --> 
  175.         <!-- 
  176.         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"   
  177.                prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/> 
  178.         --> 
  179.  
  180.       </Host> 
  181.     </Engine> 
  182.   </Service> 
  183. </Server> 
  1. tomcat2的配置文件
  2.  
  3. <?xml version='1.0' encoding='utf-8'?> 
  4. <!-- 
  5.   Licensed to the Apache Software Foundation (ASF) under one or more 
  6.   contributor license agreements.  See the NOTICE file distributed with 
  7.   this work for additional information regarding copyright ownership. 
  8.   The ASF licenses this file to You under the Apache License, Version 2.0 
  9.   (the "License"); you may not use this file except in compliance with 
  10.   the License.  You may obtain a copy of the License at 
  11.  
  12.       http://www.apache.org/licenses/LICENSE-2.0 
  13.  
  14.   Unless required by applicable law or agreed to in writing, software 
  15.   distributed under the License is distributed on an "AS IS" BASIS, 
  16.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  17.   See the License for the specific language governing permissions and 
  18.   limitations under the License. 
  19. --> 
  20. <!-- Note:  A "Server" is not itself a "Container", so you may not 
  21.      define subcomponents such as "Valves" at this level. 
  22.      Documentation at /docs/config/server.html 
  23.  --> 
  24. <Server port="18005" shutdown="SHUTDOWN"
  25.  
  26.   <!--APR library loader. Documentation at /docs/apr.html --> 
  27.   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 
  28.   <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html --> 
  29.   <Listener className="org.apache.catalina.core.JasperListener" /> 
  30.   <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html --> 
  31.   <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" /> 
  32.   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 
  33.  
  34.   <!-- Global JNDI resources 
  35.        Documentation at /docs/jndi-resources-howto.html 
  36.   --> 
  37.   <GlobalNamingResources> 
  38.     <!-- Editable user database that can also be used by 
  39.          UserDatabaseRealm to authenticate users 
  40.     --> 
  41.     <Resource name="UserDatabase" auth="Container" 
  42.               type="org.apache.catalina.UserDatabase" 
  43.               description="User database that can be updated and saved" 
  44.               factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 
  45.               pathname="conf/tomcat-users.xml" /> 
  46.   </GlobalNamingResources> 
  47.  
  48.   <!-- A "Service" is a collection of one or more "Connectors" that share 
  49.        a single "Container" Note:  A "Service" is not itself a "Container",  
  50.        so you may not define subcomponents such as "Valves" at this level. 
  51.        Documentation at /docs/config/service.html 
  52.    --> 
  53.   <Service name="Catalina"
  54.    
  55.     <!--The connectors can use a shared executor, you can define one or more named thread pools--> 
  56.     <!-- 
  57.     <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"  
  58.         maxThreads="150" minSpareThreads="4"/> 
  59.     --> 
  60.      
  61.      
  62.     <!-- A "Connector" represents an endpoint by which requests are received 
  63.          and responses are returned. Documentation at : 
  64.          Java HTTP Connector: /docs/config/http.html (blocking & non-blocking) 
  65.          Java AJP  Connector: /docs/config/ajp.html 
  66.          APR (HTTP/AJP) Connector: /docs/apr.html 
  67.          Define a non-SSL HTTP/1.1 Connector on port 8080 
  68.     --> 
  69.     <Connector port="18080" protocol="HTTP/1.1"  
  70.                connectionTimeout="20000"  
  71.                redirectPort="8443" /> 
  72.     <!-- A "Connector" using the shared thread pool--> 
  73.     <!-- 
  74.     <Connector executor="tomcatThreadPool" 
  75.                port="8080" protocol="HTTP/1.1"  
  76.                connectionTimeout="20000"  
  77.                redirectPort="8443" /> 
  78.     -->            
  79.     <!-- Define a SSL HTTP/1.1 Connector on port 8443 
  80.          This connector uses the JSSE configuration, when using APR, the  
  81.          connector should be using the OpenSSL style configuration 
  82.          described in the APR documentation --> 
  83.     <!-- 
  84.     <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" 
  85.                maxThreads="150" scheme="https" secure="true" 
  86.                clientAuth="false" sslProtocol="TLS" /> 
  87.     --> 
  88.  
  89.     <!-- Define an AJP 1.3 Connector on port 8009 --> 
  90.     <Connector port="18009" protocol="AJP/1.3" redirectPort="8443" /> 
  91.  
  92.  
  93.     <!-- An Engine represents the entry point (within Catalina) that processes 
  94.          every request.  The Engine implementation for Tomcat stand alone 
  95.          analyzes the HTTP headers included with the request, and passes them 
  96.          on to the appropriate Host (virtual host). 
  97.          Documentation at /docs/config/engine.html --> 
  98.  
  99.     <!-- You should set jvmRoute to support load-balancing via AJP ie : 
  100.     <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">          
  101.     -->  
  102.     <Engine name="Catalina" defaultHost="localhost" jvmRoute="worker2"
  103.  
  104.       <!--For clustering, please take a look at documentation at: 
  105.           /docs/cluster-howto.html  (simple how to) 
  106.           /docs/config/cluster.html (reference documentation) --> 
  107.       <!-- 
  108.       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> 
  109.       -->         
  110.       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"  channelSendOptions="8">      
  111.          
  112.        <Manager className="org.apache.catalina.ha.session.DeltaManager"     
  113.                 expireSessionsOnShutdown="false"     
  114.                 notifyListenersOnReplication="true"/>      
  115.    
  116.        <Channel className="org.apache.catalina.tribes.group.GroupChannel">      
  117.          <Membership className="org.apache.catalina.tribes.membership.McastService"     
  118.                      address="228.0.0.4"     
  119.                      port="45564"     
  120.                      frequency="500"     
  121.                      dropTime="3000"/>      
  122.          <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"     
  123.                     address="auto"   
  124.                    port="4002"     
  125.                    autoBind="100"     
  126.                    selectorTimeout="5000"     
  127.                    maxThreads="6"/>      
  128.          <!-- timeout="60000"-->      
  129.          <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">      
  130.            <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />      
  131.          </Sender>      
  132.          <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>      
  133.          <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>      
  134.          <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>      
  135.        </Channel>      
  136.    
  137.        <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"     
  138.               filter=""/>      
  139.        <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>      
  140.    
  141.        <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>      
  142.        <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>      
  143.      </Cluster>   
  144.       <!-- The request dumper valve dumps useful debugging information about 
  145.            the request and response data received and sent by Tomcat. 
  146.            Documentation at: /docs/config/valve.html --> 
  147.       <!-- 
  148.       <Valve className="org.apache.catalina.valves.RequestDumperValve"/> 
  149.       --> 
  150.  
  151.       <!-- This Realm uses the UserDatabase configured in the global JNDI 
  152.            resources under the key "UserDatabase".  Any edits 
  153.            that are performed against this UserDatabase are immediately 
  154.            available for use by the Realm.  --> 
  155.       <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
  156.              resourceName="UserDatabase"/> 
  157.  
  158.       <!-- Define the default virtual host 
  159.            Note: XML Schema validation will not work with Xerces 2.2. 
  160.        --> 
  161.       <Host name="localhost"  appBase="webapps" 
  162.             unpackWARs="true" autoDeploy="true" 
  163.             xmlValidation="false" xmlNamespaceAware="false"
  164.  
  165. <Context path="" docBase="/opt/webapps/test1" debug="0" reloadable="true" crossContext="true"/> 
  166.  
  167.         <!-- SingleSignOn valve, share authentication between web applications 
  168.              Documentation at: /docs/config/valve.html --> 
  169.         <!-- 
  170.         <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> 
  171.         --> 
  172.  
  173.         <!-- Access log processes all example. 
  174.              Documentation at: /docs/config/valve.html --> 
  175.         <!-- 
  176.         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"   
  177.                prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/> 
  178.         --> 
  179.  
  180.       </Host> 
  181.     </Engine> 
  182.   </Service> 
  183. </Server> 

2 http下配置

workers.properties配置

  1. worker.list=controller 
  2.  
  3. worker.worker1.type=ajp13 
  4. worker.worker1.host=localhost 
  5. worker.worker1.port=8009 
  6. worker.worker1.lbfactor=1 
  7. worker.worker1.cachesize=10 
  8. worker.worker1.cache_timeout=600 
  9. worker.worker1.socket_keepalive=1 
  10. worker.worker1.socket_timeout=300 
  11.  
  12. worker.worker2.type=ajp13 
  13. worker.worker2.host=localhost 
  14. worker.worker2.port=18009 
  15. worker.worker2.lbfactor=1 
  16. worker.worker2.cachesize=10 
  17. worker.worker2.cache_timeout=600 
  18. worker.worker2.socket_keepalive=1 
  19. worker.worker2.socket_timeout=300 
  20.  
  21. worker.controller.type=lb 
  22. worker.retries=3 
  23. worker.controller.balance_workers=worker1,worker2 
    worker.controller.method=B
    # 如何選擇最優的worker, B[usyness]: 選最不忙的, R[equest]: 缺省
    worker.controller.sticky_session=0
  24. worker.controller.sticky_session_force=0
  25. #ticky_session   sticky_session_force             含義

    #     true             false           SESSION會複製,有粘性
    #     true             true             SESSION不復制,有粘性
    #     false            false           SESSION會複製,無粘性
    #     false            true             SESSION會複製,無粘性
    # *注意* worker.controller.sticky_session=1,等同於worker.controller.sticky_session=true.此處指定集羣是否需要會話複製,
    #如果設爲true,則表明爲會話粘性,不進行會話複製,當某用戶的請求第一次分發到哪臺Tomcat後,後繼的請求會一直分發到此
    #Tomcat服務器上處理;如果設爲false,則表明需求會話複製。這就是說,如果你要想進行均衡負載,並在192.168.1.5和192.168.1.3
    #兩臺機器的Tomcat實例上實現集羣全局session複製,此處值要設置成false。
    #sticky_session 1: True, otherwise False, 相同session id一直訪問同一服務器   
    #sticky_session_force session id出錯狀態不返回500(Server Error), 由另一worker接手

配置uriworkermap.properties

  1. JkMount /servlet/* controller 
  2. JkMount /*.jsp controller 

配置httpd.vhost.conf

  1. NameVirtualHost *:80 
  2. <VirtualHost *:80> 
  3.     ServerAdmin [email protected] 
  4.     DirectoryIndex index.html index.htm index.jsp 
  5.     DocumentRoot "/opt/webapps/test1" 
  6.     ServerName localhost 
  7.     ErrorLog "logs/dummy-host.example.com-error_log" 
  8.     CustomLog "logs/dummy-host.example.com-access_log" common 
  9.     Include /usr/local/apache/conf/uriworkermap.properties 
  10.     <Directory "/opt/webapps/test1"
  11.         Options Indexes FollowSymLinks 
  12.         AllowOverride None 
  13.         Order allow,deny 
  14.         Allow from all 
  15.     </Directory> 
  16. </VirtualHost> 

3 測試負載均衡

 

寫一個 jsp 來進行測試

  1. <% 
  2.     out.println( "Hello, www.17rumen.com" ); 
  3.     System.out.println( "==========  test  ========" ); 
  4. %> 

刷新這個頁面(可以換瀏覽器刷新),然後查看

/usr/local/tomcat1/logs/catalina.out

/usr/local/tomcat2/logs/catalina.out

可以看到2邊都會出現==========  test  ========

說明負載成功

4 測試session複製

建一個index.jsp

  1. <%@ page contentType="text/html; charset=GBK" %> 
  2. <%@ page import="java.util.*" %> 
  3. <html><head><title>Cluster App Test</title></head> 
  4. <body> 
  5. Server Info: 
  6. <% 
  7. out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"<br>");%> 
  8. <% 
  9. out.println("<br> ID " + session.getId()+"<br>"); // 如果有新的 Session 屬性設置 
  10. String dataName = request.getParameter("dataName"); 
  11. if (dataName != null && dataName.length() > 0) { 
  12.      String dataValue = request.getParameter("dataValue"); 
  13.      session.setAttribute(dataName, dataValue); 
  14. } out.print("<b>Session 列表</b>"); Enumeration e = session.getAttributeNames(); 
  15. while (e.hasMoreElements()) { 
  16.      String name = (String)e.nextElement(); 
  17.      String value = session.getAttribute(name).toString(); 
  18.      out.println( name + " = " + value+"<br>"); 
  19.          System.out.println( name + " = " + value); 
  20.    } 
  21. %> 
  22. <form action="index.jsp" method="POST"
  23.     名稱:<input type=text size=20 name="dataName"
  24.      <br> 
  25.     值:<input type=text size=20 name="dataValue"
  26.      <br> 
  27.     <input type=submit> 
  28.    </form> 
  29. </body> 
  30. </html> 

 

 

  1. 建立/opt/webapps/test1/WEB-INF文件夾
    新建web.xml文件
    內容如下
  2.  
  3.  
  4.  
  5. <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  6. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"
  7.        <display-name>TomcatDemo</display-name> 
  8.        <distributable/> 
  9. </web-app> 

注意:在應用的web.xml加入 <distributable/> 即可

然後打開首頁同時觀察tomcat的日誌,可以發現tomcat1在運行這個頁面,同時記錄了session,然後你停止
tomcat1,會刷新頁面你會發現tomcat2依舊保存這個session,說明tomcat1和2session之間是複製了

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章