Load Balancer +session Sharing (Memcached-session-manager implementation)

Source: Internet
Author: User

Objective

  First to the big guys for a year, I wish you all: the New Year health Kang, safe!    

The formation of this article refers to a lot of people's blogs, the most should be the green years of the brother of this blog, we can first go to see, familiar with some content, because this article is direct practice, some theoretical knowledge needs to be supplemented by their own.

This article is in my previous environment LVS + keepalived + Nginx + Tomcat to achieve master-slave hot standby + load Balancing based on, so a lot of environment to build this article does not involve, do not see friends can first go to see.

Due to my big celestial restrictions on foreign sites, memcached related jar file is not very good download, here to my memcached's network address , for the needs of friends to provide convenience.

Environment Preparation and configuration

VIP (Virtual IP) is 192.168.1.200, users only need to access this IP address to obtain Web services

The Load Balancer host is 192.168.1.114 (master)----"keepalived

Standby machine for 192.168.1.112 (Brucelee)----"keepalived

Web Server A is 192.168.1.111 (youzhibing)----"Realserver + nginx + tomcat + memcached

Web Server B is 192.168.1.115 (youzhibing03)----"Realserver + nginx + tomcat + memcached

At present, the difference is the installation and configuration of memcached.

  1.memcached Installation

1.1 Dependent Installation

Memcached rely on libevent, we need to install libevent, here I just for the sake of convenience, directly with Yum rely on installed: yum-y install Libevent-devel (may not be installed, prompted to find the mirror site, then use the source to install , the source bundle has been shared in My network).

1.2 Source Installation

The installation of Memcache is installed by source code, and the source package has been shared

Decompression: TAR-ZXF memcached-1.4.25.tar.gz

CONFIGURE:CD memcached-1.4.25, then./configure--prefix=/usr/local/memcached (if Libevent is using the source installation, then it is./configure-- Prefix=/usr/local/memcached--with-libevent=/usr/local/libevent (libevent installation directory))

Make && make install

Without exception, then the memcached has been installed successfully!

  2.memcached-session-manager Configuration

2.1 Tomcat Integration

Memcached-session-manager as a tomcat extension, you only need to copy the relevant jar package to Tomcat Lib, and different versions of Tomcat corresponding to the version of the jar package are different. Let's not be mistaken (I use TOMCAT7).

Copy the jar in all to the lib of your own Tomcat directory.

2.2 Configuration file Modification

This article realizes is memcached to manage sticky non-sticky session (sticky session configuration and non-sticky session configuration only slightly different), modify the Tomcat under Conf in the Context.xml configuration file, the contents are as follows ( All tomcat in the cluster is in the same configuration, context.xml content is the same)

<?xml version= ' 1.0 ' encoding= ' utf-8 '?><!--Licensed to the Apache software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with ThisWork foradditional information regarding copyright ownership. The ASF licenses ThisFile to under the Apache License, Version 2.0( the"License"); If you don't use Thisfile except in compliance with the License. Obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0unless required by applicable law or agreed to writing, software distributed under the License are distributed on an"As is"BASIS, without warranties or CONDITIONS of any KIND, either express or implied. See the License forThe specific language governing permissions and limitations under the License.--><!--the contents of ThisFile would be loaded forEach Web application--><context> <!--Default set of monitored resources--<WatchedResource> Web-inf/web.xml</watchedresource> <!--Uncomment ThisTo disable session persistence across Tomcat restarts-<!--<manager pathname= ""/>-< !--Uncomment ThisTo enable Comet connection tacking (provides events in session expiration as well as WebApp lifecycle)-<!--<valve classname= "Org.apache.catalina.valves.CometConnectionManagerValve"/>--<manager classname= "De.javakaffee.web.msm.MemcachedBackupSessionManager" memcachednodes= "n1:192.168.1.111 : 11211,n2:192.168.1.115:11211 "<!--IP needs to be changed to the IP of your Tomcat server--sticky=" false "sessionbackupasync=" FAL Se "lockingmode=" uripattern:/path1|/path2 "requesturiignorepattern=". *\.      (ICO|PNG|GIF|JPG|CSS|JS) $ "transcoderfactoryclass=" De.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory " /></Context>

At this point the configuration is complete, do not leak the line!

  3. Service Start-up

Boot order: Tomcat-"Nginx-" memcached

Realserver start time is not required, but don't forget to start!

keepalived BOOT.

Effect Show

Because the upload picture has the size limit, I recorded the GIF picture is too big, then I also will have the effect display diagram to put in my network disk to share.

Same browser SessionID, no matter how many you open (even if you are all closed, then open);

Different browser sessionid are different;

Different computers that must be needless to say, certainly different!

Summarize

The final effect is achieved, the configuration process also has a variety of problems, and finally solved. Session sharing has always been a focus of load balancing and cluster attention, and it is a key point to be mastered by your small partners!

Session sharing there are other ways to achieve, I hope that the small partners divergent thinking, a lot of information, there is better insight, you can leave a comment in the comments area!

Something

Haven't updated the blog for a long time, here is sorry, I will be updated these two days, the small partners remember to see Oh!

Finally, the sentence: Some Xu impulse to practice quickly!

Load Balancer +session Sharing (Memcached-session-manager implementation)

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.