nginx+tomcat+memcached configuring load Balancing with session sharing learning one

Source: Internet
Author: User
Tags memcached server port tomcat server

Version info: nginx-1.9.11, Web server

Apache-tomcat-7.0.34-1,servlet container

Apache-tomcat-7.0.34-2, servlet container

jdk1.6

Memcached Memory Object Cache System


Configure Nginx Information First

Configuration path: nginx-1.9.11\conf\nginx.conf

Configuration information

   #这是基本版的   Other optimizations do not offer     server {     #访问地址与端口号          listen       80;         server_name  192.168.101.243;          #charset  koi8-r         #access_log    logs/host.access.log  main;        location / { proxy_set_header host  $host;        proxy_set_header  x-real-ip  $remote _addr;        proxy_set_header  x-forwarded-for  $proxy _add_x_forwarded_for;         #代理的发送请求服务器         proxy_pass   http://local_tomcat;proxy_connect_ Timeout   5;        proxy_send_timeout      5;         proxy_read_timeout      5;         }        #  ditto server proxy_pass  There are two Tomcat server addresses configured for the local_tomcat  configuration     pstream local_tomcat{          # weight  weight    The greater the number of accesses, the more  max_fails access fails 22 times after the server is not accessed         # fail_timeout  identity does not access the server for more than 600 seconds after re-accessing the server, with Max_ Fails with         server 192.168.101.243:18080 weight=1  max_fails=2 fail_timeout=600s;        server  192.168.101.243:18081 weight=1 max_fails=2 fail_timeout=600s;         #ip_hash; Identifies the IP fixed access server based on the first access,IP and client ip  fixed         #还有第二种配置方法就是   tomcat server.xml based on access  <engine jvmroute= "TOMCAT1" >        #需要将nginx配置在linux系统上   This requires a third-party module   No window version, the disadvantage is access to the tomcat         #地址宕机后, the session is lost.        }
Two Tomcat configurations Modify Server.xml configuration information TOMCAT1 engine label add jvmroute= "TOMCAT1" tomcat2 Engine label Add jvmroute= "TOMCAT2" to modify connector label Port number port= "18081" protocol= "http/1.1" port= "19091" protocol= "ajp/1.3" Server port= "8006" shutdown= "Shutdown" port= " 18080 "protocol=" http/1.1 "port=" 19090 "protocol=" ajp/1.3 "Server port=" 8006 "shutdown=" shutdown "run two tomcat boot Nginx Then visit

Access information for http://192.168.101.243/testin/in.jsp


Alternate page display

Tomcat_1 JSP Test Page

Tue Feb 16:10:03 CST 2016

E912147077710af041a535f3aadc66cd-n1.tomcat1

5415651 NULL




Tomcat_2 JSP Test Page

Tue Feb 16:10:30 CST 2016

E912147077710af041a535f3aadc66cd-n1.tomcat2

25383887


Configure memcached below


Run memcached.exe-d install in the cmd window to register as a service and then start the service

Copy the jar package provided by memcached into two Tomcat Lib

The copy Here is

Javolution-5.4.3.1.jar,

Memcached-session-manager-1.5.1.jar,

Memcached-session-manager-tc7-1.5.1.jar,

Msm-javolution-serializer-1.5.1.jar,

Spymemcached-2.7.3.jar

In the context.xml of two comcat, the interception request is provided here to memcached the function of getting session object

<manager

Classname= "De.javakaffee.web.msm.MemcachedBackupSessionManager"

<!--point to the address where the memcached service is located, the port that opens the service by default is 11211--

Memcachednodes= "n1:192.168.101.243:11211"

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

/>



After saving the test page as



The interface that appears after the visit is:

Tomcat_2 JSP Test Page

Tue Feb 16:20:06 CST 2016

E912147077710af041a535f3aadc66cd-n1.tomcat2

32696671


Tomcat_1 JSP Test Page

Tue Feb 16:20:26 CST 2016

E912147077710af041a535f3aadc66cd-n1.tomcat1

22994449 YANGJM


Save the value of the session object in Tomcat2, take the value of Tomcat2 saved in Tomcat1,

The ID of the session is preceded by the same but the value after the comma is different.


nginx+tomcat+memcached configuring load Balancing with session sharing learning one

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.