Nginx+tomcat+memcache Session Hold

Source: Internet
Author: User
Tags sessions tomcat server

A Tomcat profile:

Tomcat server is a free development of the source code of the Web application server, is a lightweight application server, in small and medium-sized systems and concurrent access users are not widely used, is the first choice to develop and debug JSP programs. The main application scenario is to parse the dynamic program code (JAVA) JSP program to handle the Tomcat interface

Installation of two environments:
Host name IP Address function
Server 1 192.168.3.10 Nginx accessor, tomcat client, memcached server
Server 2 192.168.3.20 Tomcat client, memcached server

Three ways to keep a session
Sessions Sticky Session binding: By implementing a unified session in the configuration of the front-end scheduler sent to the same post-originating server
Session cluster conversation cluster: Configure Tomcat to keep all Tomcat session information consistent.
Session Server Sessions Service: all session to the dedicated session service management.
Here's a third way to do session server with memcached
Architecture diagram:

Principle:
When Tomcat is down in Server1, Server2 takes over the session and reads memcached information from the local memcached.
When Server1 's memcached is down, the session information is stored locally in Server2 Tomcat, so that it is not lost.

1 Installing and configuring the Java environment

1 Download related software

2 Unpacking the Java package

3 Creating a soft connection

4 Modify environment variables to make Java work


5 to refresh

6 If the Javac is able to complete automatically, the success

2 Tomcat Installation

1 Extracting Tomcat

2 Creating a soft connection

3 Launching the Tomcat program

4 View the port whose default listener is 8080

5 Access to view

6 to see if its Java environment was successfully installed by adding time

Access to view

7 Modifying the Nginx configuration:
Nginx Installation: http://blog.51cto.com/11233559/2110593
Each time you enter 8080, change it to the default 80 port.


Restart Service

To view

Tri-Configuration Tomcat+nginx+memcahe Environment 1 environment preparation

Open a virtual host and configure the same Java environment and Tomcat as the previous one








2 experimenting: 1 Configuring reverse proxy load Balancing using Nginx



2 Restart Service

3 Verifying the Nginx polling mechanism:


and make the corresponding changes on the Server2


To view

4 Configure Web pages to write to pages in the server session cache



Forward to Server2 and view


This cannot be done with session retention, so it is necessary to use memcached to cache its sessions.

5 You need to configure the cookie to control the access client at this time



Restart Service:

View its sessions can be kept

Download Java packages to support more accurate data viewing capabilities


6 memcached Installation

Install memcached service on Server2

Start and view its 11211 port condition

Add memcahed configuration in Tomcat, where cross-storage is used, and the default Server1 access data is flushed to Server2 memcached





Restart the service to make it effective:


Check the logs to see if they are established with back-end storage relationships


Access, which is flushed to memcahed on server 2

Close memcahed

Data is switched to memcached on Server1 and remains successful

Close Tomcat


Nginx+tomcat+memcache Session Hold

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.