1.安装memcached内存数据库
yum –y install memcached
可以用telnet localhost 11211
Set abc 0 0 5
12345
get abc
2.web服务器连接memcached的jar包拷贝到tomcat的lib
3.修改server.xml里面修改Engine标签,添加jvmRoute属性,目的是查看sessionid里面带有tomcat的名字,就是这里配置的jvmRoute
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
4.配置tomcat的conf目录下的context.xml
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:192.168.17.9:11211
" sticky="false"
lockingMode="auto"
sessionBackupAsync="false"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
sessionBackupTimeout="1000" transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory" />
配置memcachedNodes属性,配置memcached数据库的ip和端口,默认11211,多个的话用空格隔开
目的?让tomcat服务器从memcached缓存里面拿session或者是放session
5.修改index.jsp,取sessionid看一看
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html lang="en">
SessionID:<%=session.getId()%>
</br>
SessionIP:<%=request.getServerName()%>
</br>
<h1>tomcat1</h1>
</html>