`

Apache2.2+Tomcat6配置集群、负载均衡、session

阅读更多

终于搞定的;

本文参照http://lxiaodao.iteye.com/blog/321000来修改的.

详细的配置过程,我把配置过程中几个不同和关键的地方重点提出来。
软件版本有所不同,罗列如下:
Apache  :apache_2.2.4-win32-x86-no_ssl.msi 1个
Tomcat:  apache-tomcat-6.0.29-windows-x86.zip   2个
mod_jk: mod_jk-1.2.26-httpd-2.2.4.so 1个 
  我在一台机器(xp)上进行测试。
把apache和tomcat安装好以后,配置过程中有如下一些地方改动或者改进。

在mod_jk-1.2.26-httpd-2.2.4.so复制到Module目录下

在D:\Apache2.2\conf\httpd.conf增加

# JK module settings Include conf/mod_jk.conf

 

 

 


 在conf目录新增mod_jk.conf ,内容如下

# Load JK Module LoadModule jk_module modules/mod_jk-1.2.26-httpd-2.2.4.so # Configure mod_jk JkWorkersFile conf/workers.properties JkMountFile conf/uriworkermap.properties JkShmFile logs/mod_jk.shm JkLogFile logs/mod_jk.log JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories JkLogLevel warn JkLogStampFormat "[%a %b %d %H:%M:%S %Y]" HostnameLookups Off <Location /jkmanager/> JkMount jkstatus Order deny,allow Deny from all Allow from 127.0.0.1 </Location>

 

 

 


 分别在Module目录下:workers.properties文件

# environment slash for Windows ps=\ worker.retries=2 worker.list=loadbalancer,jkstatus worker.s1.type=ajp13 worker.s1.host=localhost worker.s1.port=11009 worker.s1.lbfactor=1 worker.s1.connection_pool_timeout=600 worker.s1.socket_keepalive=true worker.s1.socket_timeout=60 worker.s2.type=ajp13 worker.s2.host=localhost worker.s2.port=12009 worker.s2.lbfactor=1 worker.s2.connection_pool_timeout=600 worker.s2.socket_keepalive=true worker.s2.socket_timeout=60 worker.jkstatus.type=status worker.loadbalancer.type=lb worker.loadbalancer.balance_workers=s1,s2 worker.loadbalancer.sticky_session=true

 

 

 


 uriworkermap.properties文件

/*.jsp=loadbalancer /*.action=loadbalancer /jkmanager/*=jkstatus !*.gif=loadbalancer !*.jpg=loadbalancer !*.png=loadbalancer !*.bmp=loadbalancer !*.css=loadbalancer !*.js=loadbalancer !*.htm=loadbalancer !*.html=loadbalancer !*.swf=loadbalancer

 

 

 


 然后配置tomcat6.0修改server.xml

 

<Server port="12005" 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="12080" 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="12009"  enableLookups="false" 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="s2" >

      <!--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"
               channelSendOptions="6">

        <Manager className="org.apache.catalina.ha.session.BackupManager"
                 expireSessionsOnShutdown="false"
                 notifyListenersOnReplication="true"
                 mapSendOptions="6"/>
        <!--
        <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"
                      bind="127.0.0.1"
                      address="228.0.0.4"
                      port="45564"
                      frequency="500"
                      dropTime="3000"/>
          <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                    address="127.0.0.1"
                    port="4001"
                    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;"/>

        <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
      </Cluster>

 

 

 

 


 那红色部分的端口,两个tomcat必须不一样,前三个端口只要不冲突就可以了,而Receiver  port="4001"  必须设置在4000-4010之间..网上别人说的,具体我也没做测试;
因在前面workers.properties文件定义s1,s2,所以两个server.xml分别定义为jvmRoute="s2",jvmRoute="s1" ,端口等;

然后在tomcat6.0目录下context.xml文件 修改19行为<Context distributable="true">

配置OK之后,而我测试时用的test2.jsp就直接放到jp工程下test目录下 <%@ 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>


 然后分别启动apache,tomcat1,tomcat2;在http://localhost/jp/test/test2.jsp设值为222,v222;

  

然后在加上tomcat的端口去访问,所得值一样的.

后在加上tomcat的端口去访问,所得值一样的.

 

 

从上面测试可以看到session复制是正确的..

0
0
分享到:
评论

相关推荐

    Apache+Tomcat+Linux集群和均衡负载(Session同步复制

    Apache+Tomcat+Linux集群和均衡负载(Session同步复制

    Windows下Apache2.2+Tomcat6配置集群、负载均衡、session共享

    在Windows环境下,Apache2.2和Tomcat6的组合是一个常见的Web服务器架构,用于搭建集群、实现负载均衡和处理session共享。Apache作为前端反向代理服务器,负责分发请求到后端的多个Tomcat实例,以提高应用的可用性和...

    apache2.2+tomcat6集群配置

    Apache2.2与Tomcat6集群配置是一种常见的Web服务架构,用于提高网站的可用性和可扩展性。在Windows环境下,这种配置可以实现负载均衡,确保即使单个服务器出现故障,整个系统仍然能继续运行,同时分散请求以降低单一...

    Apache+Tomcat+JK 实现集群负载均衡文档

    Apache+Tomcat+JK 实现集群负载均衡是一种常见的Web服务器和应用服务器的部署方式,它能够提高系统的可用性和响应速度,实现服务的高并发处理。本文将详细介绍如何配置这一环境。 首先,我们需要准备以下软件: 1. ...

    apache2.2+tomcat6.0负载均衡配置软件

    Apache 2.2 和 Tomcat 6.0 的负载均衡配置是提高Web应用程序性能和可扩展性的重要技术。在高流量环境下,通过将工作负载分散到多个Tomcat实例上,可以确保服务的稳定性和响应速度,同时避免单一服务器过载。下面我们...

    Apache2.2+tomcat7+jk+jdk1.6

    本配置"Apache2.2+tomcat7+jk+jdk1.6"旨在实现一个稳定且可靠的环境,特别关注于session的共享与管理,以解决多服务器间的session一致性问题。 Apache2.2是Apache HTTP Server的第2.2版本,提供了强大的静态内容...

    Apache2.2+JBOSS 5 集群配置

    Apache2.2+JBOSS 5 集群配置主要涉及在Linux环境下构建高可用性和负载均衡的服务器集群,以提升应用服务的稳定性和处理能力。以下是详细的知识点: 1. **JBoss集群架构**: JBoss 集群可以采用两种架构:客户端...

    Apache2.2 tomcat-6.0.18负载均衡与集群

    在Apache2.2+Tomcat集群中,可以实现会话复制,确保用户在集群中的任何一台服务器上都能继续其之前的会话。Tomcat的集群功能依赖于org.apache.catalina.ha.session.JvmRouteBinderValve,它添加了JVM路由信息到...

    apache_server+Tomcat7集群负载均衡session共享

    通过上述配置,Apache Server 2.2和Tomcat7集群可以提供高可用和高效的Web服务,同时通过session共享保证了用户会话的连续性,提升了用户体验。提供的LICENSE、NOTICE和README文件通常包含了软件授权信息、版权声明...

    Windows+Nginx+Tomcat做负载均衡同时实现session共享Demo

    总之,“Windows+Nginx+Tomcat做负载均衡同时实现session共享Demo”是一个实践性强的教学资源,它涵盖了Web服务集群中的关键技术和最佳实践,对于学习和提升系统架构能力非常有帮助。通过深入理解和实践这个Demo,...

    apache+tomcat集群配置

    本文将详细介绍如何配置 Apache + Tomcat 集群,包括安装 Apache 和 Tomcat 服务器、配置 mod_jk 模块、配置 Apache 和 Tomcat 服务器、配置负载均衡控制器等。 一、安装 Apache 服务器 首先,需要安装 Apache ...

    Apache+Tomcat+JK配置负载均衡

    Apache+Tomcat+JK配置负载均衡是Web服务器与应用服务器集群的一种常见组合,用于实现高可用性和高并发处理能力。Apache作为前端服务器,通过JK模块(mod_jk)与后端的Tomcat应用服务器进行通信,将HTTP请求分发到多...

    Apache+Tomcat集群和负载均衡及Session绑定

    【Apache+Tomcat 集群与负载均衡及Session...通过以上配置,Apache+Tomcat集群可以实现高效的负载均衡和高可用性,同时通过Session绑定确保用户会话的连续性。注意定期监控和优化集群性能,以应对不断变化的业务需求。

    apache2.2 tomcat6.0 集群与负载均衡

    总结来说,Apache 2.2 与 Tomcat 6.0 集群和负载均衡的配置是一项复杂但至关重要的任务,涉及到服务器复制、会话共享、负载均衡策略以及故障恢复等多个环节。通过精心设计和实施,可以构建出稳定、高效的Web服务环境...

    Apache2.4+Tomcat7服务器集群配置及软件.rar

    在集群配置中,Apache通常作为反向代理服务器,负责接收来自客户端的请求,并根据负载均衡策略将请求转发到后台的Tomcat实例。Apache2.4.43引入了多项优化,提高了服务器的稳定性和响应速度。 Tomcat 7是一款开源的...

    Apache2.2与tomcat7 集群配置

    总结来说,Apache2.2与Tomcat7集群配置涉及的技术主要包括Apache的mod_jk模块、集群理论、负载均衡策略、会话复制、故障转移以及相关配置文件的设置。熟练掌握这些知识点,对于构建高性能的Java Web服务至关重要。

    Apache+Tomcat服务器集群配置详细步骤

    本文将详细介绍如何在一机双Tomcat环境下搭建Apache+Tomcat集群,并深入解析其中的关键配置和技术细节。 #### 二、Apache+Tomcat集群的优势 1. **高可靠性(HA)**:通过集群管理软件实现在主服务器发生故障时,备份...

    apache2.2+mod_JK+Tomcat7+Terracotta3.7 集群(重要)

    在Tomcat集群中,Terracotta可以实现session复制和共享,确保用户在集群中的任意节点之间切换时,其会话状态保持一致,避免了session丢失的问题。 集群配置文件tc-config.xml是Terracotta的配置文件,用于定义集群...

Global site tag (gtag.js) - Google Analytics