Nginx/redis/Tomcat集群实现session共享
一.版本
Tomcat : 7.0.82
JDK: 1.8.0_151
二. 配置步骤
1.将下面三个jar包放到$CATALINA_HOME/lib下:
commons-pool2-2.3.jar
jedis-2.5.2.jar
tomcat-redis-session-manager-2.0.0.jar.
2.在各个tomcat节点添加如下配置:
#vi /usr/local/tomcat/conf/context.xml <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" /> <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" host="xxx" --redis数据库ip port="6379" --redis端口号 database="0" --存储Session的Redis库编号 maxInactiveInterval="60"/> --Session失效的间隔(秒)
3.重启各个节点tomcat服务
4.nginx中配置tomcat集群转发
upstream tomcat { server 172.16.68.224:8083 weight=1; server 172.16.68.224:8084 weight=1; } server { listen 80; server_name 172.16.68.224; location / { proxy_pass http://tomcat; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
5.可编写jsp页面或者访问redis进行session测试
Reference: https://blog.csdn.net/hutingxiang/article/details/80347403
https://blog.csdn.net/Jerome_s/article/details/52658946