session之memcache

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了session之memcache相关的知识,希望对你有一定的参考价值。

nginx服务器配置:192.168.200.111
[root@nginx ~]# hostname nginx
[root@nginx ~]# bash
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
upstream tomcat_pool {
server 192.168.200.112:8080 weight=1 max_fails=1 fail_timeout=10s;
server 192.168.200.113:8080 weight=1 max_fails=1 fail_timeout=10s;
}
location / {
root html;
index index.html index.htm;
proxy_pass http://tomcat_pool;
proxy_set_header Host $http_host;
}
[root@nginx ~]# killall -1 nginx
第一台tomcat服务器配置:192.168.200.112
[root@node1 ~]# vim /usr/local/tomcat8/webapps/ROOT/session.jsp
Session ID:<%= session.getId() %> <BR>
SessionPort:<%= request.getServerPort() %>
<% out.println("This tomcat server 192.168.200.112"); %>
[root@node1 ~]# vim /usr/local/tomcat8/webapps/ROOT/session.jsp
Session ID:<%= session.getId() %> <BR>
SessionPort:<%= request.getServerPort() %>
<% out.println("This tomcat server 192.168.200.112"); %>
[root@node1 ~]# yum -y install libevent memcached
[root@node1 ~]# memcached -u root -m 512M -n 10 -f 2 -d -vvv -c 512
[root@node1 ~]# mkdir session
上传memcached的jar包
[root@node1 ~]# cp session/* /usr/local/tomcat8/lib/
[root@node1 ~]# vim /usr/local/tomcat8/conf/context.xml
<Context>
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="memA:192.168.200.112:11211 memB:192.168.200.113:11211"
requestUrilgnorePattern=".*(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
</Context>
[root@node1 ~]# /usr/local/tomcat8/bin/shutdown.sh
[root@node1 ~]# /usr/local/tomcat8/bin/startup.sh
[root@node1 ~]# ls session/ | while read line ; do rm -rf /usr/local/tomcat8/lib/$line; done
第二台tomcat服务器配置:192.168.200.113
同上

 

以上是关于session之memcache的主要内容,如果未能解决你的问题,请参考以下文章

缓存之Memcache

Django之session与分页

jsp之session对象

PHP会话控制之session_start

会话之Session

六十一:Flask.Session之flask操作session