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

Source: Internet
Author: User

nginx+tomcat+redissession Shared

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:

nginx.conf Configuration:

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 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)

<Context>

<valve classname= "Com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve"/>

<managerclassname= "Com.orangefunction.tomcat.redissessions.RedisSessionManager"

host= "192.168.1.223" <!--Redis Address --

port= "6379" <!--Redis Ports --

paassword= "Tomcat" <!--Redis Password -

database= "0" <!-- Storage Session Redis Library number--

maxinactiveinterval= <!--Session failure interval (seconds)- -

/>

</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?

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/88/3D/wKioL1fstSuSo7J-AABg--EPx3Y146.png-wh_500x0-wm_3 -wmp_4-s_1886208190.png "style=" Float:none; "title=" 1.png "alt=" Wkiol1fstsuso7j-aabg--epx3y146.png-wh_50 "/>

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/88/41/wKiom1fstSvAwmtyAABe9xZuils155.png-wh_500x0-wm_3 -wmp_4-s_320410243.png "style=" Float:none; "title=" 2.png "alt=" Wkiom1fstsvawmtyaabe9xzuils155.png-wh_50 "/>


You can see that although the server changes from Tomcata to TOMCATB, the session creation time has not changed, which completes the session sharing.


This article is from the "[email protected]" blog, please be sure to keep this source http://renzhiyuan.blog.51cto.com/10433137/1857743

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.