Nginx+memcached+tomcat cluster configuration

Source: Internet
Author: User
Tags serialization

This is mainly a demonstration operation on Win7 64.

      • Web application Building
      • Memcached installation Configuration Start
      • Tomcat Configuration
        • Required JAR Packages
          • Memcached-session-manager
          • Serialization of
        • Contextxml Configuration
      • Nginx Installation Configuration Start
      • Test
      • Reference

Web application Building

Simple to construct a Web application, this is not described here, specifically to access my GitHub.
For ease of display, make a difference on success.jsp, one plus 8080, one plus 8081.

memcached installation, configuration, startup

This example uses 2 memcached nodes, all on one machine.

The operation on Win7 64. Resources can be downloaded on this link I am a link.
After decompression, enter cmd into this directory, remember to run as an administrator .

Installation

memcached  -d install

Run

-d start

You can also start multiple memcached services and refer to this link.

Create

create "Memcached Server" start= auto binPath= "memcached_path -d runservice -m 32 -p 11311 -l 127.0.0.1" DisplayName= "Memcached Server"

Note Modify the port, default is 11211
can be accessed via telnet: telnet 127.0.0.1 11211
Telnet interface quit to exit

To start, stop, and uninstall Memcached Server Commands:

"Memcached Server"  //启动"Memcached Server"  //停止delete"Memcached Server"  //卸载该服务

You can see the Memcached service on Task Manager

Tomcat Configuration

This time with 2 tomcat7.0.62 examples

Tomcat cluster configuration, each node in the cluster is shared by the session in the cache memcached by sharing: If a Tomcat service on one machine is stopped, Session data on other peer servers can still be read from the memcached cache, so there is no problem with session loss.

Use Memcached-session-manager, official documentation.

Tomcat configuration consists of two main aspects, first need to download the required package, placed in the Tomcat installation directory under the Lib directory (strictly speaking should be $catalina_home/lib/)
The jar required by the first MSM, the jar required for serialization,
A second configuration context.xml

Required Jar Pack Memcached-session-manager

MAVEN Configuration for Tomcat 7
The following 3 jar packages are required;
Memcached-session-manager-version.jar,
Memcached-session-manager-tc7-version.jar,
Spymemcached-version.jar

Can be downloaded from maven below

<dependency>    <groupId>de.javakaffee.msm</groupId>    <artifactId>memcached-session-manager-tc7</artifactId>    <version>1.8.3</version></dependency>
Serialization of

4 Kinds of serialization

Kryo-serializer:<dependency>      <groupId>De.javakaffee.msm</groupId>      <artifactid>Msm-kryo-serializer</artifactid>      <version>Version</version>  </Dependency>Javolution:<dependency>      <groupId>De.javakaffee.msm</groupId>      <artifactid>Msm-javolution-serializer</artifactid>      <version>Version</version>  </Dependency>XStream<dependency>      <groupId>De.javakaffee.msm</groupId>      <artifactid>Msm-xstream-serializer</artifactid>      <version>Version</version></Dependency>Flexjson:<dependency>      <groupId>De.javakaffee.msm</groupId>      <artifactid>Msm-flexjson-serializer</artifactid>      <version>Version</version>  </Dependency>

The jar packages required for various serialization are as follows:
- Kryo-serializer: msm-kryo-serializer, Kryo-serializers, Kryo, Minlog, Reflectasm, ASM
- Javolution-serializer: Msm-javolution-serializer, Javolution
- Xstream-serializer: msm-xstream-serializer, XStream, Xmlpull, xpp3_min
- Flexjson-serializer: Msm-flexjson-serializer, Flexjson

$CATALINA _home/lib/add jar as follows

Context.xml Configuration

That is, modify the contents of the context node in the $catalina_home/conf/context.xml file to submit the MSM configuration.
This includes the use of memcached to manage sticky session and non-sticky sessions and the use of membase to manage non-sticky sessions.
The sample is based on the 2 memcached instances on a single host, and the example uses a serialization method of Kryo.

This time use sticky session to manage, as for non-sticky can be self-configuration or next time to add, configured as follows, 2 tomcat configuration.

<Context>    ...  <Manager   className="de.javakaffee.web.msm.MemcachedBackupSessionManager"  memcachedNodes="n1:localhost:11211,n2:localhost:11311"          sticky="false" sessionBackupAsync="false"         lockingMode="auto"         requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"/></Context>  
Nginx installation, configuration, startup

Download stable version on official website,

After extracting it into the directory,

start nginx  // 启动

In this way, the Nginx service is started. Open Task Manager to view the Nginx.exe process, with two processes showing up, consuming system resources, which is fairly small. Then open the browser, enter HTTP://127.0.0.1/can see Nginx welcome page, very friendly.

-s stop          // 停止nginx-s reload       // 重新加载配置文件-s quit          // 退出nginx

By default, Nginx uses the default configuration file, nginx.conf, to modify it as follows:

#user Nobody;worker_processes  2;#error_log Logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;Events{worker_connections  1024x768;}http{includeMime.types;Default_typeApplication/octet-stream;Log_formatMain'$remote _addr - $remote _user [$time _local] "$request"                      '$status $body _bytes_sent '$http _referer '                      ' "$http _user_agent" "$http _x_forwarded_for" ';Access_logLogs/access.log main;Sendfile         on;#tcp_nopush on;    #keepalive_timeout 0;    #keepalive_timeout;    #gzip on;    Upstreamlocalhost {#ip_hash;        Serverlocalhost8080weight=1;Serverlocalhost8081weight=1; }Server{Listen        the;server_namelocalhostCharSetutf-8;#charset koi8-r;        #access_log Logs/host.access.log main;         Location/ {RoothtmlIndexIndex.html index.htm;Proxy_pass http://localhost;Proxy_connect_timeout 2s;Proxy_set_headerX-real-ip$remote _addr;Proxy_set_headerX-forwarded-for$proxy _add_x_forwarded_for; } Location ~ ^/(web-inf)/{DenyAll }#error_page 404/404.html;        # REDIRECT Server error pages to the static page/50x.html        #        Error_page    - 502 503 504/50x.html; Location=/50x.html {Roothtml }# Proxy The PHP scripts to Apache listening on 127.0.0.1:80        #        #location ~ \.php$ {        # Proxy_pass http://127.0.0.1;        #}        # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000        #        #location ~ \.php$ {        # root HTML;        # Fastcgi_pass 127.0.0.1:9000;        # Fastcgi_index index.php;        # Fastcgi_param Script_filename/scripts$fastcgi_script_name;        # include fastcgi_params;        #}        # Deny access to. htaccess files, if Apache ' s document Root        # concurs with Nginx ' s one        #        #location ~/\.ht {        # deny all;        #}}# Another virtual host using mix of ip-, name-, and port-based configuration    #    #server {    # Listen 8000;    # listen somename:8080;    # server_name Somename alias Another.alias;    # location/{    # root HTML;    # index index.html index.htm;    #    }    #}    # HTTPS Server    #    #server {    # Listen 443 SSL;    # server_name localhost;    # ssl_certificate Cert.pem;    # Ssl_certificate_key Cert.key;    # Ssl_session_cache shared:ssl:1m;    # ssl_session_timeout 5m;    # ssl_ciphers high:!anull:! MD5;    # ssl_prefer_server_ciphers on;    # location/{    # root HTML;    # index index.html index.htm;    #    }    #}}
Test

Landing page

Success Page
Success1

Success2

When the tomcat (8080) is turned off, call Tomcat (8081) to display the SUCCESS2;
When you close a memcached service, the display is normal.

Reference

Nginx+memcached+tomcat Cluster configuration practice (Sticky Session)
Start multiple memcached services in the same Windows machine
Msm–memcached_session_manager Introduction and use
Memcached-session-manager Configuration
Installation and configuration of Windows Nginx

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Nginx+memcached+tomcat cluster configuration

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.