windows 下 nginx + tomcat + redis 集群实现session共享

windows 下 nginx + tomcat + redis 集群实现session共享

nginx:nginx-1.14.0
redis : Redis-x64-3.2.100
tomcat 版本:apache-tomcat-6.0.32

nginx 配置:

http {
upstream test{
server 127.0.0.1:8081 weight=1;
server 127.0.0.1:8082 weight=1;
server 127.0.0.1:8083 weight=1;
}
server {

    location /test/ {
        proxy_pass http://test; 
        proxy_set_header   Host             $host;  
        proxy_set_header   X-Real-IP        $remote_addr;  
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;    
    }

}

}

redis 配置

修订redis.windows.conf

# 端口绑定
bind 0.0.0.0

# 数据存储
save ""

# 最大内存
maxmemory 512M
# 最大内存策略
maxmemory-policy allkeys-lru

tomcat 配置:

部署3个tomcat

redis 依赖包

放置在tomcat/lib 目录下
tomcat-redis-session-manager-1.2-tomcat-6.jar
commons-pool-1.6.jar
jedis-2.1.0.jar

百度地址:https://pan.baidu.com/s/1nEyidPqp9ffHhiolWzDlTw

配置context.xml

<Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve" />
<Manager className="com.radiadesign.catalina.session.RedisSessionManager"
         host="127.0.0.1"
         port="6379" 
         database="0" 
         maxInactiveInterval="1800"/>

配置server.xml

Server SHUTDOWN port:8081,8082,8083
Connector HTTP/1.1 :8081,8082,8083
Connector AJP/1.3 :8019,8029,8039

分别在webapps下新建test目录,新建文件 session.jsp,内容如下:

<%@ page language="java" %>
<html>
  <head><title>session test</title></head>
  <body>
    <h1><font color="blue">Tomcat1</h1>
    <table align="centre" border="1">
      <tr>
        <td>Session ID</td>
    <% session.setAttribute("my.name","zhangSan"); %>
        <td><%= session.getId() %></td>
      </tr>
      <tr>
        <td>Created on</td>
        <td><%= session.getCreationTime() %></td>
     </tr>
    </table>
  </body>
</html>

按顺序启动服务

redis
nginx
tomcat

session 同步测试

浏览器打开地址,如果session id一致,则配置成功
http://127.0.0.1/test/session.jsp
这里写图片描述
这里写图片描述
这里写图片描述

猜你喜欢

转载自blog.csdn.net/huryer/article/details/81294889