{"id":4833,"date":"2021-01-17T19:26:21","date_gmt":"2021-01-17T11:26:21","guid":{"rendered":"http:\/\/www.menglanglang.cn\/?p=4833"},"modified":"2021-01-17T19:30:54","modified_gmt":"2021-01-17T11:30:54","slug":"%e4%bd%bf%e7%94%a8-memcached-%e8%a7%a3%e5%86%b3-tomcat-%e7%9a%84-session-%e4%b8%80%e8%87%b4%e6%80%a7%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/www.menglanglang.cn\/?p=4833","title":{"rendered":"\u4f7f\u7528 memcached \u89e3\u51b3 tomcat \u7684 session \u4e00\u81f4\u6027\u95ee\u9898"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">\u73af\u5883\u51c6\u5907<\/h3>\n\n\n\n<p>nging\uff1a\u5b89\u88c5\u5728&nbsp;192.168.220.243\uff08node243\uff09\uff0c\u7248\u672c\u4e3a nginx-1.19.6.tar.gz\u3002<\/p>\n\n\n\n<p>memcached\uff1a\u5b89\u88c5\u5728 192.168.220.100\uff08node100\uff09\uff0c\u7248\u672c\u4e3a1.4.4\u3002<\/p>\n\n\n\n<p>tomcat\uff1a\u5b89\u88c5\u5728 192.168.220.71\uff08Rserver71\uff09\u548c 192.168.220.72\uff08Rserver72\uff09\uff0c\u7248\u672c\u4e3a 7\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u4e00\u6b65\uff0c\u5b89\u88c5 memcached \u5e76\u542f\u52a8<\/h3>\n\n\n\n<p>\u5728 node100 \u673a\u5668\u4e0a\u5b89\u88c5 memcached \u670d\u52a1\uff0c\u5e76\u542f\u52a8\u670d\u52a1\u3002\u76f8\u5173\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>\u5b89\u88c5\u670d\u52a1\uff1ayum -y install memcached<\/p>\n\n\n\n<p>\u542f\u52a8\u670d\u52a1\uff1aservice memcached start<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u4e8c\u6b65\uff0c\u6d4b\u8bd5 memcached \u670d\u52a1<\/h3>\n\n\n\n<p>memcached \u670d\u52a1\u542f\u52a8\u540e\uff0c\u9ed8\u8ba4\u7aef\u53e3\u4e3a11211\u3002<\/p>\n\n\n\n<p>\u547d\u4ee4\uff1atelnet 192.168.220.100 11211<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"257\" width=\"573\" alt=\"\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/20210117171242296.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3R6aHV3Yg==,size_16,color_FFFFFF,t_70\"\/><\/p>\n\n\n\n<p>\u67e5\u770b\u8f6f\u4ef6\u4fe1\u606f\u547d\u4ee4\uff1astats<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"728\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/20210117190756807.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3R6aHV3Yg==,size_16,color_FFFFFF,t_70\" width=\"561\"\/><img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/www.menglanglang.cn\/b2d28b5f-6611-4ef7-b959-f5fdc42e6df0\" width=\"15\" height=\"15\"\/>\u200b<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u4e09\u6b65\uff0c\u5b89\u88c5 tomcat \u5e76\u542f\u52a8<\/h3>\n\n\n\n<p>\u8fd9\u91cc\u5728\u53e6\u5916\u4e24\u53f0\u6d4b\u8bd5\u673a Rserver71 \u548c Rserver72 \u4e0a\u5206\u522b\u5b89\u88c5 tomcat7 \u5e76\u542f\u52a8 tomcat \u670d\u52a1\u3002<\/p>\n\n\n\n<p>\u8be6\u7ec6\u6b65\u9aa4\u7565\uff0c\u8bf7\u81ea\u884c\u67e5\u9605\u3002\u6d4b\u8bd5\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"156\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/20210117172202916.png\" width=\"442\"\/><img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/www.menglanglang.cn\/c6dc02b7-25da-4ee5-aec5-6c8990a139a8\" width=\"15\" height=\"15\"\/>\u200b<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"153\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/20210117172216387.png\" width=\"507\"\/><img loading=\"lazy\" decoding=\"async\" src=\"blob:http:\/\/www.menglanglang.cn\/fbebb897-221a-4e5d-b6d4-b7998ac8aee9\" width=\"15\" height=\"15\"\/>\u200b<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u56db\u6b65\uff0c\u914d\u7f6e nginx \u5e76\u6d4b\u8bd5<\/h3>\n\n\n\n<p>\u4fee\u6539 nginx \u914d\u7f6e\u6587\u4ef6 nginx.conf\uff0c\u6dfb\u52a0\u4e24\u4e2a tomcat \u7684\u8bbf\u95ee\u914d\u7f6e\uff0c\u8ba9\u5176\u8f6e\u5faa\u8bbf\u95ee\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>&nbsp; &nbsp; #gzip &nbsp;on;<\/p><p><strong>&nbsp; &nbsp; upstream myweb {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; server 192.168.220.71:7070 weight=5;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; server 192.168.220.72:7070 weight=5;<br \/>&nbsp; &nbsp; }<\/strong><\/p><p>&nbsp; &nbsp; server {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; listen &nbsp; &nbsp; &nbsp; 80;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; server_name &nbsp;192.168.220.243;<\/p><p>&nbsp; &nbsp; &nbsp; &nbsp; #charset koi8-r;<\/p><p>&nbsp; &nbsp; &nbsp; &nbsp; #access_log &nbsp;logs\/host.access.log &nbsp;main;<\/p><p>&nbsp; &nbsp; &nbsp; &nbsp; location \/ {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <strong>proxy_pass http:\/\/myweb;<\/strong><br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root &nbsp; html;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; index &nbsp;index.html index.htm;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; }<\/p><p>&nbsp; &nbsp; &nbsp; &nbsp; ...<\/p><p>&nbsp; &nbsp;}<\/p><\/blockquote>\n\n\n\n<p>\u8bbf\u95ee nginx\uff0c\u6d4b\u8bd5\u8f6e\u5faa\u8bbf\u95ee tomcat\u3002<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"159\" width=\"900\" alt=\"\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/20210117191151295.png\"\/><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u4e94\u6b65\uff0c\u4e0a\u4f20\u76f8\u5173&nbsp;jar \u5305\u5230 tomcat \u76ee\u5f55<\/h3>\n\n\n\n<p>\u4e0a\u4f20 memcached-session-manager \u53ca\u76f8\u5173\u4f9d\u8d56\u5305\u5230 tomcat \u7684 lib \u76ee\u5f55\u3002<\/p>\n\n\n\n<p>\u5305\u4e0b\u8f7d\u5730\u5740\uff1a\u94fe\u63a5\uff1a<a href=\"https:\/\/pan.baidu.com\/s\/1xmRU0ic78u8-wvjeTmGVCw\">https:\/\/pan.baidu.com\/s\/1xmRU0ic78u8-wvjeTmGVCw<\/a> \uff08\u63d0\u53d6\u7801\uff1amzdc\uff09<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u516d\u6b65\uff0c\u4fee\u6539 tomcat \u7684 server.xml \u914d\u7f6e\u6587\u4ef6<\/h3>\n\n\n\n<p>\u4fee\u6539\u914d\u7f6e\uff1a&lt;Engine name=\"Catalina\" defaultHost=\"localhost\" <strong>jvmRoute=\"jvm71\"<\/strong>&gt;<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u914d\u7f6e\u662f session \u4e2d tomcat \u7684\u6807\u8bc6\u540d\u3002<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"86\" width=\"796\" alt=\"\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/20210117172521225.png\"\/><\/p>\n\n\n\n<p>72 \u673a\u5668\u540c\u7406\u4fee\u6539\u4e3a&nbsp; <strong>jvmRoute=\"jvm72\"<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u4e03\u6b65\uff0c\u4fee\u6539 tomcat \u6d4b\u8bd5\u9875\u9762\u83b7\u53d6 session \u4fe1\u606f<\/h3>\n\n\n\n<p>\u547d\u4ee4\uff1avi webapps\/ROOT\/index.jsp<\/p>\n\n\n\n<p>\u5185\u5bb9\u4fee\u6539\u4e3a\u5982\u4e0b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>&lt;html&gt;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &lt;h1&gt;tomcat7-71&lt;\/h1&gt;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; SessionID:&lt;%=session.getId()%&gt;&lt;\/br&gt;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; SessionIP:&lt;%=request.getServerName()%&gt;&lt;\/br&gt;<br \/>&lt;\/html&gt;<\/p><\/blockquote>\n\n\n\n<p>72 \u673a\u5668\u540c\u7406\u4fee\u6539\uff0c\u4fee\u6539\u540e\u5206\u522b\u91cd\u542f\u4e24\u4e2a tomcat\u3002<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"234\" width=\"900\" alt=\"\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/20210117191432201.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3R6aHV3Yg==,size_16,color_FFFFFF,t_70\"\/><\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"236\" width=\"900\" alt=\"\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/20210117191452841.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3R6aHV3Yg==,size_16,color_FFFFFF,t_70\"\/><\/p>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\u5728 tomcat \u8f6e\u5faa\u8bbf\u95ee\u65f6\uff0csessionId \u4e5f\u5728\u4e0d\u505c\u53d1\u751f\u53d8\u5316\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u516b\u6b65\uff0c\u6dfb\u52a0 memcached \u914d\u7f6e<\/h3>\n\n\n\n<p>\u5206\u522b\u4fee\u6539\u4e24\u4e2a tomcat \u7684 context.xml \u914d\u7f6e\u6587\u4ef6\uff0c\u6dfb\u52a0\u5173\u4e8e memcached \u90e8\u5206\u7684\u914d\u7f6e\u4fe1\u606f\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>&lt;Context&gt;<\/p><p>&nbsp; &nbsp; &lt;!-- Default set of monitored resources --&gt;<br \/>&nbsp; &nbsp; &lt;WatchedResource&gt;WEB-INF\/web.xml&lt;\/WatchedResource&gt;<\/p><p>&nbsp; &nbsp; &lt;!-- Uncomment this to disable session persistence across Tomcat restarts --&gt;<br \/>&nbsp; &nbsp; &lt;!--<br \/>&nbsp; &nbsp; &lt;Manager pathname=\"\" \/&gt;<br \/>&nbsp; &nbsp; --&gt;<\/p><p>&nbsp; &nbsp; &lt;!-- Uncomment this to enable Comet connection tacking (provides events<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;on session expiration as well as webapp lifecycle) --&gt;<br \/>&nbsp; &nbsp; &lt;!--<br \/>&nbsp; &nbsp; &lt;Valve className=\"org.apache.catalina.valves.CometConnectionManagerValve\" \/&gt;<br \/>&nbsp; &nbsp; --&gt;<\/p><p><strong>&lt;Manager className=\"de.javakaffee.web.msm.MemcachedBackupSessionManager\"<br \/>&nbsp; &nbsp; &nbsp; &nbsp; memcachedNodes=\"m1:192.168.220.100:11211\"<br \/>&nbsp; &nbsp; sticky=\"false\"<br \/>&nbsp; &nbsp; lockingMode=\"auto\"<br \/>&nbsp; &nbsp; sessionBackupAsync=\"false\"<br \/>&nbsp; &nbsp; &nbsp; &nbsp; requestUriIgnorePattern=\".*\\.(ico|png|gif|jpg|css|js)$\"<br \/>sessionBackupTimeout=\"1000\" transcoderFactoryClass=\"de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory\" \/&gt;<\/strong><\/p><p>&lt;\/Context&gt;<\/p><\/blockquote>\n\n\n\n<p>\u4fee\u6539\u540e\u5206\u522b\u91cd\u542f\u4e24\u4e2a tomcat \u670d\u52a1\uff0c\u518d\u6b21\u901a\u8fc7 nginx \u8bbf\u95ee\u6d4b\u8bd5\u8f6e\u5faa\uff0c\u53ef\u4ee5\u770b\u5230 sessionId \u5df2\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"235\" width=\"900\" alt=\"\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/20210117191729423.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3R6aHV3Yg==,size_16,color_FFFFFF,t_70\"\/><\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"234\" width=\"900\" alt=\"\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/2021011719174687.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3R6aHV3Yg==,size_16,color_FFFFFF,t_70\"\/><\/p>\n\n\n\n<p>\u901a\u8fc7\u914d\u7f6e\u548c\u6d4b\u8bd5\uff0c\u4e24\u4e2a tomcat \u7684 session \u4e00\u81f4\u6027\u95ee\u9898\uff0c\u5df2\u7ecf\u901a\u8fc7 memcached \u5f97\u4ee5\u89e3\u51b3\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u6d4b\u8bd5\u8fc7\u7a0b\u4e2d\uff0c\u53d1\u73b0\u8bbf\u95ee nginx \u65f6\uff0ctomcat \u4e0d\u8f6e\u5faa\u5207\u6362\uff0c\u662f Chrome \u6d4f\u89c8\u5668\u7684\u95ee\u9898\uff0c\u6362\u6d4f\u89c8\u5668\u6d4b\u8bd5\uff0c\u6216\u8005\u7ed9 nginx \u505a\u4e0b\u914d\u7f6e\u5373\u53ef\uff0c\u914d\u7f6e\u4e3a\uff1a<strong>location \/favicon.ico {}<\/strong>\uff0c\u8be6\u7ec6\u95ee\u4f60\u539f\u56e0\u53ef\u4ee5\u53c2\u770b\u94fe\u63a5\uff1ahttps:\/\/bbs.csdn.net\/topics\/393650853<\/p>\n\n\n\n<p>\u539f\u6587\u94fe\u63a5\uff1a<a href=\"https:\/\/blog.csdn.net\/tzhuwb\/article\/details\/112752190\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/blog.csdn.net\/tzhuwb\/article\/details\/112752190<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73af\u5883\u51c6\u5907 nging\uff1a\u5b89\u88c5\u5728&nbsp;192.168.220.243\uff08node243\uff09\uff0c\u7248\u672c\u4e3a nginx- [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[705],"tags":[602,837,719,288,839,838],"class_list":["post-4833","post","type-post","status-publish","format-standard","hentry","category-it-frame","tag-linux","tag-memcached","tag-nginx","tag-tomcat","tag-839","tag-838"],"_links":{"self":[{"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/posts\/4833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4833"}],"version-history":[{"count":2,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/posts\/4833\/revisions"}],"predecessor-version":[{"id":4836,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/posts\/4833\/revisions\/4836"}],"wp:attachment":[{"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4833"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}