没有搭建好nginx环境的同学,请参考我的上一篇博客 nginx负载均衡初探 实验环境 win7:tomcat6+jdk6+memcached linux:vmware9+ubuntu+jdk6+nginx+tomcat6+memcached 首先在window是下安装memcached memcached-1.2.6-win32-bin.zip,64 位下也可以 memcached.exe -d install 安装为windows服务 memcached.exe -d start 设置服务为开机启动 其次配置memcached的端口,HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\memcached Server ImagePath:"D:\java学习\nginx负载均衡配置\windows安装包\memcached.exe" -p 12345 -m 128 -d runservice 其中12345是memcached的端口,在tomcat的conf/context..xml中需要用到 配置tomcat的conf/context..xml linux、windows的tomcat的conf/context.xml配置方法一样<?xml version='1.0' encoding='utf-8'?> <Context> <WatchedResource>WEB-INF/web.xml</WatchedResource> <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:192.168.0.108:12345 n2:192.168.110.130:12345" requestUriIgnorePattern=".*/.(png|gif|jpg|css|js)$" sessionBackupAsync="false" sessionBackupTimeout="100" transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory" copyCollectionsForSerialization="false" /> </Context> 在tomcat的lib下放入五个jar包
javolution-5.4.3.1.jar ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ linux下安装memcached libevent-1.3.tar.gz memcached-1.2.2.tar.gz 使用tar解压~~ 首先安装libevent 进入/usr/local/memcache install files/libevent-1.3解压后的libevent目录 #可以在后面加入参数,安装路径.不加的话默认安装到usr/local/lib ./configure #编译 make #安装 make install 查看是否安装成功 进入 ls usr/local/bin/lib/*.so,显示如下则是安装成功 zhengx@zhengx-virtual-machine:/$ ls usr/local/lib/*.sousr/local/lib/libevent.so 其次,在linux下安装memcached 进入/usr/local/memcache install files/libevent-1.3/memcached-1.2.2。解压后的memcached目录 #–with-libevent=/usr/local/lib一定要加上去,否则安装失败!/usr/local/lib为libevent的安装目录
./configure –with-libevent=/usr/local/lib 如有不能创建目录的error,执行sudo chmod 777 /usr/local -R 启动memcached的方式 /usr/local/bin/memcached -d -m 256 -u root -l 192.168.1.5 -p 12345 -c 256 -P /data/memcached/memcached.pid 配置linux的tomcat,和win7一样 然后在浏览器中http://192.168.110.130/t/,session不会变了
再次刷新,注意查看会话id(session_id)
在tomcat1中session.setAttribute(key,value)。在tomcat2中session.getAttribute(key);测试
|