1.准备jar包,是最麻烦的一步,我选择kryo的序列化方案,javolution序列化死活弄不通,总是报错.google上又说是bug,不支持,启动就是报错 -rw-r--r-- 1 tomcat tomcat 3085 3月 25 2014 minlog-1.2.jar -rw-r--r-- 1 tomcat tomcat 147019 3月 9 2015 memcached-session-manager-1.8.2.jar -rw-r--r-- 1 tomcat tomcat 29329 3月 9 2015 msm-kryo-serializer-1.8.2.jar -rw-r--r-- 1 tomcat tomcat 62112 3月 9 2015 kryo-serializers-0.11.jar -rw-r--r-- 1 tomcat tomcat 43398 3月 9 2015 asm-3.2.jar -rw-r--r-- 1 tomcat tomcat 94830 3月 9 2015 kryo-1.04.jar -rw-r--r-- 1 tomcat tomcat 11615 3月 9 2015 reflectasm-1.01.jar -rw-r--r-- 1 tomcat tomcat 459447 3月 9 2015 spymemcached-2.11.1.jar -rw-r--r-- 1 tomcat tomcat 10407 6月 6 19:41 memcached-session-manager-tc8-1.8.2.jar 2.弄两个tomcat实例,server.xml配置 <Host name="localhost" appBase="webapps" unpackWARs="false" autoDeploy="false"> <Context path="" docBase="/opt/apps/8181/" reloadable="false" /> cat /opt/apps/8181/index.jsp <%@ page language="java" %> <html> <head><title>TomcatA</title></head> <body> <h1><font color="red">TomcatA.magedu.com</font></h1> <table align="centre" border="1"> <tr> <td>Session ID</td> <% session.setAttribute("magedu.com","magedu.com"); %> <td><%= session.getId() %></td> </tr> <tr> <td>Created on</td> <td><%= session.getCreationTime() %></td> </tr> </table> </body> </html> 另外一个8282就行 3.编译memcached libevent-2.0.22-stable memcached-1.4.24 vim /etc/init.d/memcached 从别人博客找到的 #!/bin/bash # # Init file for memcached # # chkconfig: - 86 14 # description: Distributed memory caching daemon # # processname: memcached # config: /etc/sysconfig/memcached . /etc/rc.d/init.d/functions ## Default variables PORT="11211" USER="nobody" MAXCONN="1024" CACHESIZE="256" RETVAL=0 prog="/usr/local/memcached/bin/memcached" desc="Distributed memory caching" lockfile="/var/lock/subsys/memcached" start() { echo -n $"Starting $desc (memcached): " daemon $prog -d -p $PORT -u $USER -c $MAXCONN -m $CACHESIZE RETVAL=$? [ $RETVAL -eq 0 ] && success && touch $lockfile || failure echo return $RETVAL } stop() { echo -n $"Shutting down $desc (memcached): " killproc $prog RETVAL=$? [ $RETVAL -eq 0 ] && success && rm -f $lockfile || failure echo return $RETVAL } restart() { stop start } reload() { echo -n $"Reloading $desc ($prog): " killproc $prog -HUP RETVAL=$? [ $RETVAL -eq 0 ] && success || failure echo return $RETVAL } case "$1" in start) start ;; stop) stop ;; restart) restart ;; condrestart) [ -e $lockfile ] && restart RETVAL=$? ;; reload) reload ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart|condrestart|status}" RETVAL=1 esac exit $RETVAL ######################## chkconfig --add memcached chkconfig memcached on service memcached start cp -r /etc/init.d/memcached /etc/init.d/memcached2 改端口,再起一个 4.context配置 tomcat a的配置 <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:172.1.1.212:11211,n2:172.1.1.212:11212" failoverNodes="n2" requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" transcoderFactoryClass="de.javakaffee.web.msm.JavaSerializationTranscoderFactory" /> tomcat b的配置 <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:172.1.1.212:11211,n2:172.1.1.212:11212" failoverNodes="n1" requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" transcoderFactoryClass="de.javakaffee.web.msm.JavaSerializationTranscoderFactory" /> 5.启动报这个信息就是正确的 信息: -------- - finished initialization: - sticky: true - operation timeout: 1000 - node ids: [n1] - failover node ids: [n2] - storage key prefix: null -------- 6.前段用nginx还是apache,自己喜欢那个用那个 7.测试,http://ip,你会看到 session id是不变的。
时间: 2024-11-05 22:18:37