The usual way to keep the session:
1 , some agents (such as Nginxip_hash)
1 , using the database to store the session
2 , using cookies to store session
3 , using Redis to store sesssion (Memcache can also)
......
Environment:
|
192.168.1.220 nginx centos6.6 Port:
Version: 1.9.2
192.168.1.224 tomcata centos6.6 Port: 8080
192.168.1.225 TOMCATB centos6.6 Port: 8090
version: jdk:1.7.0_75 Tomcat: 7.0.54
192.168.1.223 Redis 3.0.5 Port: 6379
|
Configure session hold and test:
| 1234567891011121314 |
nginx.conf配置:upstream www.tomcatcluster.com { zone myapp1 64k; server 192.168.1.224:8080 weight=1 max_fails=2fail_timeout=30s; server 192.168.1.218:8090 weight=1 max_fails=2fail_timeout=30s;}server { listen 80 default; server_name www.tomcat.com; location / { proxy_pass http://www.tomcatcluster.com; }} |
Tomcata:TOMCATB
Session hold:
Edit Tomcat configuration file Context.xml (both Tomcata and TOMCATB operations)
| 1234567891011 |
<Context><Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve"/><ManagerclassName="com.orangefunction.tomcat.redissessions.RedisSessionManager" host="192.168.1.223"<!-- Redis地址 --> port="6379"<!-- Redis端口 --> paassword="tomcat" <!-- Redis密码 --> database="0"<!-- 存储Session的Redis库编号 --> maxInactiveInterval="60"<!-- Session失效的间隔(秒) -->/></Context>mv commons-pool2-2.2.jar jedis-2.7.2.jar tomcat-redis-session-manage-tomcat7.jar /usr/local/tomcat-7.0.54/lib/ |
How do I test session sessions to maintain?
You can see that although the server changes from Tomcata to TOMCATB, the session creation time has not changed, which completes the session sharing.
Nginx+tomcat cluster +redis (memcache) session sharing!