Nginx+tomcat8+memcached Implementing session Sharing

Source: Internet
Author: User
Tags memcached serialization tomcat server

Installing nginx-1.13.8

Installing jdk1.8.0_144

Installing tomcat-8.5.24

Installing memcached-1.4.15

Download TOMCAT8 connection memcached required jar Package

Official reference: https://github.com/magro/memcached-session-manager/wiki/SetupAndConfiguration# Decide-which-serialization-strategy-to-use

Configure Nginx

Here is my main profile, please modify it according to your own situation

Worker_processes 1;

Events {

Worker_connections 1024;

}

HTTP {

Include Mime.types;

Default_type Application/octet-stream;

Sendfile on;

Keepalive_timeout 65;

Upstream Tomcat_nginx {

Server 192.168.3.58:8080;

Server 192.168.3.54:8080;

Server 192.168.3.31:8080;

}

server {

Listen 80;

server_name localhost;

Location/{

proxy_pass Http://tomcat_nginx;

}

Error_page 502 503 504/50x.html;

Location =/50x.html {

root HTML;

}

}

}

Configuring the Nginx startup script

#! /bin/bash

# Description:startup script for webserver on CentOS. CP It IN/ETC/INIT.D and

# chkconfig--add nginx && chkconfig nginx on

# then you can use Server command control Nginx

#

# chkconfig:2345 08 99

# Description:starts, stops Nginx


Set-e

Path= $PATH:/usr/local/nginx/sbin/

desc= "Nginx Daemon"

Name=nginx

daemon=/usr/local/nginx/sbin/$NAME

Configfile=/usr/local/nginx/conf/nginx.conf

#PIDFILE =/var/run/nginx.pid

Pidfile=/usr/local/nginx/logs/nginx.pid

Scriptname=/etc/init.d/$NAME


# Gracefully Exit If the package has been removed.

Test-x $DAEMON | | Exit 0


D_start () {

$DAEMON-C $CONFIGFILE | | Echo-n "Already Running"

}


D_stop () {

Kill-quit ' Cat $PIDFILE ' | | Echo-n "Not Running"

}


D_reload () {

Kill-hup ' Cat $PIDFILE ' | | Echo-n "can ' t reload"

}


Case "$" in

Start

Echo-n "Starting $DESC: $NAME"

D_start

echo "."

;;

Stop

Echo-n "Stopping $DESC: $NAME"

D_stop

echo "."

;;

Reload

Echo-n "Reloading $DESC configuration ..."

D_reload

echo "Reloaded."

;;

Restart

Echo-n "Restarting $DESC: $NAME"

D_stop

Sleep 1

D_start

echo "."

;;

*)

echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2

Exit 3

;;

Esac

Exit 0

It feels like a githup account is needed to manage the configuration file.


Start Nginx

Write a test page for Tomcat, which is available in both formats (put in webapps/root/)

    <body bgcolor= "green" >      

    <center>     

& nbsp   <%=  request.getsession (). GetId ()  %>     

    192.168.3.31

    this is tomcat 1!

    </center>

    </body>

<%@ page contenttype= "Text/html;charset=utf-8" iselignored= "false"%>

Sessionid:<%=session.getid ()%><br>

Sessionip:<%=request.getservername ()%> <BR>

Sessionport:<%=request.getserverport ()%>

<% Out.println ("This isTomcat server!"); %>

Start Tomcat

Tomcat Access Test

Nginx Access Test

Tomcat8+memcached Implementing session Sharing

Download the jar Package

Different versions of Tomcat use a jar package that may differ, this test uses tomcat-8.5.24

Jar Package Detail List and Tomcat (note: Jedis-2.9.0.jar is a jar bundle that connects to Redis)

Modify Conf/context.xml (per tomcat)

Here is Non-sticky sessions + Kryo, recommended reference official documentation: https://github.com/magro/memcached-session-manager/wiki/ Setupandconfiguration

<Context>

<WatchedResource>WEB-INF/web.xml</WatchedResource>

<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

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

memcachednodes="n1:192.168.3.31:11211"

Sticky= "false"

Sessionbackupasync= "false"

Lockingmode= "None"

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

sessionbackuptimeout= "1000"

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

/>

</Context>

Memcachednodes is the specified memcached, can have more than one node, N1 is a label, others by guessing

Start memcached, restart Tomcat


Access test

Using Redis instead of memcached

Inside the jar package, the Jedis-2.9.0.jar is the jar package that connects to Redis, the official explanation for details

Test failed (⊙﹏⊙) b

A bunch of incompatible versions of the problem, try all the jar packs with the latest results no

Error

Missing jar package or version conflict

Reference: https://github.com/magro/memcached-session-manager/wiki/SetupAndConfiguration# Decide-which-serialization-strategy-to-use

Https://wenku.baidu.com/view/caecc5cf6037ee06eff9aef8941ea76e58fa4abd.html

Nginx+tomcat8+memcached Implementing session Sharing

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.