Nginx+tomcat+memcached sharing Session-id

Source: Internet
Author: User
Tags memcached openssl

I. Node information

192.168.1.133

Nginx

192.168.211.133

|

----------------------------------

| |

Tomcata (211.40) TOMCATB (211.132)

Memcachea (211.136) Memcachb (211.137)

Configure fixed IP

Turn off SELinux

Turn off iptables, boot does not start

Two. Principle

through Nginx proxy access back end Tomcat , and achieve memcache the same browser as the one accessed by the Session is the same.

Three. Deployment

Installation of the Tomcat service

A. Install the development environment Jdk-6u27-linux-i586.bin (32-bit)

installation package Download: Http://pan.baidu.com/s/1skqesVF nm9q

    • chmod +x jdk-6u27-linux-i586.bin

    • ./jdk-6u27-linux-i586.bin

For more information on what data registration collects and

How it's managed and used, see:

Http://java.sun.com/javase/registration/JDKRegistrationPrivacy.html


Press Enter to continue .....



Done.

Note: When the above information is installed, installing the JDK often reports many errors

eq: /lib/ld-linux.so.2:bad ELF interpreter description 64-bit system installed 32-bit program

Workaround: yum-y install glibc.i686 (recommended with CentOS from the Yum source, can be installed)


    • MV JDK1.6.0_27/ETC/USR/LOCAL/JDK

    • Defining variables used by the Tomcat service runtime

[email protected] ~]# VI/ETC/BASHRC

Export JRE_HOME=/USR/LOCAL/JDK

Export Java_bin=/usr/local/jdk/bin

Export path= $JRE _home/bin: $PATH

Export classpath=.: $JRE _home/lib/dt.jar: $JRE _home/lib/tools.jar

Export Jre_home java_bin PATH CLASSPATH

: Wq

[Email protected] ~]# SOURCE/ETC/BASHRC

B. Installing the Tomat package apache-tomcat-6.0.32.tar.gz

installation package Download: Http://pan.baidu.com/s/1boizwy7 2gwu

    • TAR-ZXVF apache-tomcat-6.0.32.tar.gz

    • MV Apache-tomcat-6.0.32/usr/local/tomcat

    • NETSTAT-UNLATP |grep:8080

    • Cd/usr/local/tomcat/bin

    • ./startup.sh

    • NETSTAT-UNLATP |grep:8080

TCP 0 0::: 8080:::* LISTEN 1879/java

Test: ip:8080 Whether the test page appears

Similarly: The second machine is set above, note IP


Installation of the Memcached service

A. Installing development tools

    • Yum-y Install GCC make gcc-c++

B. Installing the Memcached Software

Note: libevent-2.0.15-stable.tat.gz must be installed before installing memcached software

installation package Download: Libevent:http://pan.baidu.com/s/1o6tpqia Lwyu

MEMCACHED:HTTP://PAN.BAIDU.COM/S/1I3LS6M5 8e52

    • TAR-ZXVF libevent-2.0.15-stable.tar.gz

CD libevent-2.0.15-stable

./configure && make && make install

    • TAR-ZXVF memcached-1.4.5.tar.gz

CD memcached-1.4.5

./configure && make && make install

    • Vim/etc/ld.so.conf.d/libevent.conf

/usr/local/lib/

: Wq

Ldconfig-v

    • /usr/local/bin/memcached-u root-m 100m-n 10-f 2-d-VVV

Options:

-H View Help information

-p Specifies the port number of the memcached listener default 11211

-L memcached Server IP address

-U memcached the user identity used when running the program must be the root user

-m specifies how much physical memory to use this computer default 64M

The maximum number of links to the-C memcached service

-VVV Show Details

-N Chunk the minimum space of a size is how many units of bytes

-F Chunk Size growth multiplier by default 1.25 times times

-D starts in the background

    • Netstat-utnlap | grep:11211

Knowledge Points:

kill-9 PID number kills memcached process (process number)

Pkill-9 memcached Kill memcached Process (process name)

Killall-9 memcached kills all memcached processes

    • Test memcached:

[[Email protected] ~]# telnet localhost 11211

Trying 192.168.1.10 ...

Connected to 192.168.1.10 (192.168.1.10).

Escape character is ' ^] '.

Set name 0 180 3//0 fixed format 180 180 seconds 3 3 bytes

Jim

STORED

Get Name

VALUE Name 0 3

Jim

END

Quit

Connection closed by foreign host.

Similarly: The second machine is configured as above, note IP


Tomcat and memcached Connection tool Memcached+session+manager

installation package Download: Http://pan.baidu.com/s/1YYfiY u9dl

A. Unpacking the installation package

B. Installation and Configuration

Install and configure the following on two tomcat servers:

    • CD session

    • CP *.jar/usr/local/tomcat/lib/

    • cd/usr/local/tomcat/conf///Configure Tomcat configuration file to connect to the specified memcached server

VI contest.conf//insert the following lines of text

<Context>

......

......

<manager classname= "De.javakaffee.web.msm.MemcachedBackupSessionManager"

memcachednodes= "n1:192.168.211.142:11211 n2:192.168.211.143:11211"

Failovernodes= "N2"

Requesturilgnorepattern= ". *\ (ICO|PNG|GIF|JPG|CSS|JS) $"

Transcoderfactoryclass= "De.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"

/>

</Context>

    • Restart the Tomcat service

Installation of Nginx Service

A. Install the development environment

    • Yum-y Install GCC make gcc-c++

    • Yum-y install pcre pcre-devel OpenSSL openssl-devel

B. Installing Nginx Service

installation package Download: Http://pan.baidu.com/s/1c1nhg2G 5QPN

    • Useradd Nginx

    • TAR-ZXVF nginx-1.0.5.tar.gz

    • CD nginx-1.0.5

    • ./configure--prefix=/usr/local/nginx--user=nginx--group=nginx--with-http_ssl_module--with-http_stub_status_ Module

    • Make && make install

    • Cd/usr/local/nginx/conf

    • Modify the configuration file (the original file is best backed up)

HTTP {

Upstream Tomcatgrp {

Server 192.168.1.10:8080;

Server 192.168.1.20:8080;

}

server {

...

...

Location/{

root HTML;

Index index.html index.htm;

Proxy_pass http://tomcatgrp;

}

......

......

}

}

: Wq

    • test that the configuration file is correct./nginx-t

    • ./nginx


Test

A. By entering the Nginx URL to see if the color of the page is flexible, the session is not changed

Test page Download :Http://pan.baidu.com/s/1bjNxTG 9br2

The test is also placed in the cd/usr/local/tomcat/webapps/root/directory, and two tomcat tests will be changed, each tomcat color is not the same can be












This article from "Tidypet" blog, reproduced please contact the author!

Nginx+tomcat+memcached sharing Session-id

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.