Nginx+tomcat cluster +redis (memcache) session sharing!

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.