Apache + Tomcat + mod_jk实现集群服务及session共享

实现效果:用apache 分发请求到tomcat中的对应的项目

原理:

环境说明:

操作系统:win7   64位

Javajdk: 1.7 
Apache:httpd-2.2.25-win32-x86-no_ssl.msi    (本地安装路径:D:\Program Files (x86)\Apache2.2\)
Tomcat: 7.0.42  ( http://tomcat.apache.org/download-70.cgi ),如果在同一台机器上模拟,下载zip版本. 实例中展示了2个节点
mod_jk: mod_jk1.2.30_x64:  ( http://tomcat.apache.org/download-connectors.cgi )

安装步骤:

1.安装jdk
2.安装Apache2.2,使用默认设置,并且安装路径中不要空格.
3.解压tomcat
4.拷贝mod_jk.so到Apache安装路径的modules文件夹下

配置步骤

修改Apache配置:

关于修改涉及到的文件httpd.conf和workers.properties文件可以下载一份mod_jk的源码包参看

1.修改Apache配置文件httpd.conf(笔者路径:D:\Program Files (x86)\Apache2.2\conf\httpd.conf), 在最后一行末尾添加:

include "D:\Program Files (x86)\Apache2.2\conf\mod_jk.conf"2. 在httpd.conf 同目录下新建mod_jk.conf文件
#指定模块路径
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 /* controller

#指定jk的日志输出文件
JkLogFile logs/mod_jk.log
#指定日志级别,我这里设置的警告
JkLogLevel warn
#包含标准的mod_jk行为 (默认)
#info
#包含错误信息
#error
#用来配置log文件的日期/时间格式. 使用strftime()的格式化字符串,默认是[%a %b %d %H:%M:%S %Y]
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"    

#Options Description(选项的说明)
# %b 发送的字节, 不包括 HTTP headers (CLF format)
# %B 发送的字节, 不包括 HTTP headers
# %H 协议
# %m 请求方式(get/post)
# %p 服务器响应请求的规范端口.
# %q 查询字符串 (如果存在以?开头,否则是空串)
# %r 请求的第一行.
# %s HTTP状态码
# %T 请求间隔, 处理请求耗费的时间 秒.微秒
# %U 请求的url路径,不包含查询字符串.
# %v 响应请求的规范服务器名字
# %V 根据UseCanonicalName设置的服务器名字.
# %w Tomcat worker 名字
#JkRequestLogFormat 设置个人用户请求的log格式.
JkRequestLogFormat "%w %V %T"

3.在httpd.conf同目录下新建 workers.properties文件

#这里可以配置任意多个Tomcat,此处配置了2个Tomat服务器.
#host和port根据自己实际配置.实例配置的是本机两个tomcat,分别使用不同的端口.避免冲突
#如果Tomcat不再同一机器上,没必要改端口的。

#server 列表
worker.list=controller,status,tomcat1,tomcat2 

#========tomcat1========

worker.tomcat1.port=9988        #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.host=192.168.0.47        #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1  #server的加权比重,值越高,分得的请求越多

#========tomcat2========

worker.tomcat2.port=9999        #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat2.host=192.168.0.47        #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1        #server的加权比重,值越高,分得的请求越多 

#========controller,负载均衡控制器========
worker.controller.type=lb

#指定此负载平衡器负责的Tomcat应用节点。

worker.controller.balance_workers=tomcat1,tomcat2   #指定分担请求的tomcat

#此处指定集群是否需要会话复制,如果设为true,则表明为会话粘性,不进行会话复制,当某用户的请求第一次分发到哪台
#Tomcat后,后继的请求会一直分发到此Tomcat服务器上处理;如果设为false,则表明需求会话复制。
worker.controller.sticky_session=false
#描述是用于httpd自身状态监控的status
worker.status.type=status

4.在httpd.conf同目录下新建 uriworkermap.properties文件(未测试是否对集群有影响)

/*=controller
/jkstatus=status
!/*.gif=controller
 !/*.jpg=controller
!/*.png=controller
!/*.css=controller
!/*.js=controller
!/*.htm=controller
!/*.html=controller

修改Tomact配置:(tomcat 6.0.36  可以实现集群  ,但是session没有共享。原因未找到)(tomcat 7.0.42 实现集群及session共享)

以 tomcat 7.0.42  为实例

1.修改分发tomcat对应的service.xml文件,保证Apache对应的 workers.properties中的AJP13的connector的port.

<!-- 定义一个AJP 1.3 连接端口为9988 ,默认值为8009,这里我们改成我们自己定义的9988端口 -->
<Connector port="9988" protocol="AJP/1.3" redirectPort="8443" />

2.增加jvmRoute的值,保证同workers.properties里边配置的值一致

<!--增加jvmRoute,值为在Apache中配置的list集群结点中的值,这里定义为tomcat1结点-->
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

3.去掉默认注释掉的集群配置

<!--取消集群结点相关的注释,该句默认值注释掉的,我们需要配置集群所以去掉注释,让其起作用-->
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

4.实例中我们的两个tomcat结点在同一台机器上,所以还需要保证protocol="HTTP/1.1"的端口不一致.不然本地的两个tomcat会起冲突

下面为笔者实例中解决同一台机器上多个tomcat服务器之间端口冲突做的修改.

实例测试

1.在web.xml文件中增加

<distributable/>

2.编写测试jsp代码 
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.text.SimpleDateFormat"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Tomcat集群测试</title>
  </head>

  <body>
        服务器信息:

    <%
      String dtm = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date());
      System.out.println("["+request.getLocalAddr()+":"+ request.getLocalPort()+"]" + dtm);
      out.println("<br>["+request.getLocalAddr()+":" +request.getLocalPort()+"]" + dtm+"<br>");
    %>

    session分发:
    <%
        session.setAttribute("name","dennisit");
        System.out.println("[session分发] session id:"+session.getId());
        out.println("<br>[session分发] session id: " + session.getId()+"<br>");
    %>
  </body>
</html>

3.测试负载均衡与session分发

将项目部署到每个集群结点中,即实例中的tomcat_node1和tomcat_node2,依次移动Apache和tomcat服务器,tomcat服务器之间的启动顺序随意.这里Apache端口使用默认的80.

上面是在FireFox中运行项目后刷新3次执行的效果,可以看到2个tomcat分发结点之间轮流负载.而且两台服务器上的session值是一样的.说明session分发成功.

两台Tomcat服务器日志打印输出结果:

错误解决:

(1)apache 服务器无法加载jk代理

原因:apache 和 mod_jk  版本差异导致。解决办法,将mod_jk.so替换为 mod_jk-1.2.31-httpd-2.2.3.so。

(2)apache 服务器无法启动

原因:httpd.conf  配置文件有误。首次安装可以启动。你改动有误。

其他

附上tomcat  6   与tomcat  7   server.xml  对比代码:

tomcat  6

<?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="8005" 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="9008" 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="9988" enableLookups="false" protocol="AJP/1.3" redirectPort="8443" />

    <!--For clustering-->
    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
<!--    <Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
                 managerClassName="org.apache.catalina.cluster.session.DeltaManager"
                 expireSessionsOnShutdown="false"
                 useDirtyFlag="true"
                 notifyListenersOnReplication="true">

            <Membership
                className="org.apache.catalina.cluster.mcast.McastService"
                mcastAddr="228.0.0.4"
                mcastPort="45564"
                mcastFrequency="500"
                mcastDropTime="3000"/>

            <Receiver
                className="org.apache.catalina.cluster.tcp.ReplicationListener"
                tcpListenAddress="auto"
                tcpListenPort="4001"
                tcpSelectorTimeout="100"
                tcpThreadCount="6"/>

            <Sender
                className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
                replicationMode="pooled"
                ackTimeout="15000"
                waitForAck="true"/>

            <Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
                   filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>

            <Deployer className="org.apache.catalina.cluster.deploy.FarmWarDeployer"
                      tempDir="/tmp/war-temp/"
                      deployDir="/tmp/war-deploy/"
                      watchDir="/tmp/war-listen/"
                      watchEnabled="false"/>

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

-->

    <!-- 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"/>
      -->        

      <!-- 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">
      <!-- <context docBase= "e:\webapps\tomcat_apche" path="/tomcat_apche"  debug="0" reloadable="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 -->
        <!--
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
        -->

      </Host>
    </Engine>
  </Service>
</Server>

tomcat  6  死活没弄出来session 共享  即使加上各位大神的如下代码。(无意冒犯,就事说事。)

http://www.linuxidc.com/Linux/2012-08/69311p2.htm

tomcat  7

<?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="8005" shutdown="SHUTDOWN">
  <!-- 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 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="9008" 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="9988" 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="tomcat1">

    <!--<Engine name="Catalina" defaultHost="localhost">-->

      <!--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 &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>

比较不错的大牛参考博文:

Apache+Tomcat负载均衡两种session共享方式的设置:http://blog.sina.com.cn/s/blog_5f53615f0100p4fj.html

Apache + Tomcat + mod_jk实现集群服务:http://www.linuxidc.com/Linux/2015-02/114231.htm

Apache2+Tomcat7+mod_jk2.2.3集群负载均衡配置(目前最强悍)

				
时间: 2024-10-05 06:56:29

Apache + Tomcat + mod_jk实现集群服务及session共享的相关文章

Apache + Tomcat + mod_jk实现集群服务

Tomcat中的集群原理是通过组播的方式进行节点的查找并使用TCP连接进行会话的复制. 实现效果:用apache 分发请求到tomcat中的对应的项目 环境说明: 操作系统:window xp Javasdk: 1.7 Apache: 2.2.14    (本地安装路径:D:\Apache2.2\) Tomcat: 7.0.42  ( http://tomcat.apache.org/download-70.cgi ),如果在同一台机器上模拟,下载zip版本. 实例中展示了2个节点 mod_jk

Nginx+Tomcat+Memcached 实现集群部署时Session共享

一.简介 我们系统经常要保存用户登录信息,有Cookie和Session机制,Cookie客户端保存用户信息,Session在服务端保存用户信息,如果浏览器不支持Cookie或者用户把Cookie禁掉了,Cookie就用不了,还有不同的浏览器采用不用方式保存Cookie,所以我们采用Session服务端来保存,上一节我们有介绍了Tomcat集群部署,怎么样集群的Tomcat对同个用户请求的都能获取保存在Session的用户信息,采用了Memcached管理Session,Memcached 是一

Linux下使用Apache的Httpd+Mod_jk+Tomcat搭建Web集群服务

Linux下使用Apache的Httpd+Mod_jk+Tomcat搭建Web集群服务 目的 ?? 使用多个tomcat服务器来对请求进行分流,防止单个服务器压力过重.这里为了简单,只使用两个tomcat. 软件 apache httpd-2.2.31(下载地址:https://httpd.apache.org/download.cgi) apache tomcat-7.0.69(下载地址:https://tomcat.apache.org/download-70.cgi) tomcat-con

Windows下Apache+Tomcat实现应用集群

Windows下Apache+Tomcat实现应用集群1 环境依赖:windows.jdk1.6.Apache2.2.tomcat6.02 Jdk1.6安装2.1 略3 安装Apache(2.2.27)3.1 下载:从Apache官网http://httpd.apache.org/download.cgi下载httpd-2.2.25-win32-x86-openssl-0.9.8y.msi:3.2 安装:双击上一步下载的安装程序,持续下一步直到完成:安装向导成功完成,左面右下角托盘中会出现Apa

Memcached 在集群中的 session 共享存储

以下是 PHP Web 环境集群中的 session 共享存储设置: [[email protected] ~]# cat /etc/php.inisession.save_handler = memcache session.save_path = "tcp://192.168.5.131:11211" 配置完在 phpinfo 页面中查看:

如何在tomcat集群中实现Session共享

转自:http://www.toutiao.com/i6388049068718817794/ Apache集群实现Tomcat的Session共享配置其实很简单,在Tomcat自带的文档中有详细的说明( /docs/cluster-howto.html ),只不过是英语的,所以联合 下面根据说下怎么配置吧: 1.既然是集群肯定要多准备几个Tomcat来模拟,比如分别为Tomcat01.Tomcat02.Tomcat03. 如果各Tomcat程序放在不同的机器上,那么就不会有端口的冲突.如果是放

nginx整合tomcat集群并做session共享----测试案例

最近出于好奇心,研究了一下tomcat集群配置,并整合nginx,实现负载均衡,session共享,写篇记录,防止遗忘.---------菜鸡的自我修炼. 说明:博主采用一个web项目同时部署到两台tomcat下,(tomcat-A,tomca-B),使用nginx做反向代理,按照设置的权值,将请求分发到后台的tomcatA/tomcat-B,并且实现session共享. 配置好本地域名指向:修改host文件:添加 127.0.0.1  www.domain.com.cn 新建项目:tiny-d

nginx负载均衡集群中的session共享说明

在网站使用nginx+php做负载均衡情况下,同一个IP访问同一个页面会被分配到不同的服务器上,如果session不同步的话,就会出现很多问题,比如说最常见的登录状态. 下面罗列几种nginx负载均衡中session同步的方式 1)不使用session,换用cookiesession是存放在服务器端的,cookie是存放在客户端的,我们可以把用户访问页面产生的session放到cookie里面,就是以cookie为中转站.你访问web服务器A,产生了session然后把它放到cookie里面,当

Apache+Tomcat负载均衡集群搭建

1.所需软件 apache_2.2.4-win32-x86-no_ssl,apache服务器 mod_jk-apache-2.2.4连接器,连接apache和tomcat apache-tomcat-6.0.33tomcat服务器 2.软件安装 2.1apache 安装 一直下一步,到此界面: 填写域名或localhost都可: 安装完成后,启动访问localhost,界面如下则安装成功: 2.2tomcat安装 省略,网上资料大把大把. 3.集群配置 3.1apache与mod_jk.so整合