侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

nginx+tomcat+redis完成session共享

2023-11-27 星期一 / 0 评论 / 0 点赞 / 51 阅读 / 4182 字

准备两个tomcat,修改相应的端口 名称 IP 端口 tomcat版本 JDK tomcat1 127.0.0.1 8080 7.0.75 1.7.0_25 tomcat2 127.0

准备两个tomcat,修改相应的端口

名称        IP    端口        tomcat版本   JDK

tomcat1 127.0.0.1         8080        7.0.75     1.7.0_25

tomcat2 127.0.0.1         9090         7.0.75     1.7.0_25

 

修改nginx.conf加上:

  upstream tomcats {

         server 127.0.0.1:8080;

         server 127.0.0.1:9090;

         }

修改nginx.conf的location成

[html] view plain copy

 

    location / { 

        root   html; 

        index  index.html index.htm; 

        proxy_pass http:// tomcats; 

     } 

 

 

启动nginx。

 

下载tomcat-redis-session-manager相应的jar包,主要有三个:

http://download.csdn.net/detail/qinxcb/8279761

http://central.maven.org/maven2/redis/clients/jedis/2.5.2/jedis-2.5.2.jar

http://central.maven.org/maven2/org/apache/commons/commons-pool2/2.0/commons-pool2-2.0.jar

下载完成后拷贝到$TOMCAT_HOME/lib中

修改两tomcat的context.xml:

    <Context>        

        <!-- Default set of monitored resources --> 

        <WatchedResource>WEB-INF/web.xml</WatchedResource>        

        <!-- Uncomment this to disable session persistence across Tomcat restarts --> 

        <!--

        <Manager pathname="" />

        -->        

        <!-- Uncomment this to enable Comet connection tacking (provides events 

             on session expiration as well as webapp lifecycle) --> 

        <!--

        <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />

        -->        

      <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" /> 

      <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" 

       host="127.0.0.1" 

       port="6379" 

       database="0" 

       maxInactiveInterval="60" /> 

    </Context> 

 

 

在tomcat/webapps/test放一个index.jsp

 

<%@ page  pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>

<%= session.getCreationTime() %>

<%=("80="+session.getId())%>

为区分第二个写成

<%=("90="+session.getId())%>

 

启动tomcat

通过访问http://127.0.0.1/test/

 

 

刷新:

 

可以看到虽然Server从80变为90,但session 的创建时间没有变化,这就完成了session共享。

广告 广告

评论区