1.安装yum -y install memcache
2.
安装 yum -y install nginx
配置nginx集群
upstream www.test.com {
server 192.168.0.1
server 192.168.0.2
}
server {
listen 80;
server_name www.test.com
location / {
proxy_pass http://www.test.com
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
3.在tomcat1和tomcat2 配置 session共享
修改两个tomcat的 conf/server.xml
在<host></host>之间 插入
在tomcat1中加入
<Context docBase="/opt/tomcat1/webapps/ROOT" path="" reloadable="true">
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:localhost:11211,n2:localhost:11311"
failoverNodes="n1"
sticky="false"
requestUriIgnorePattern=".*\.(png|gif|jpg|css|js)$"
sessionBackupAsync="false"
sessionBackupTimeout="100"
ranscoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory" copyCollectionsForSerialization="false" />
</Context>
在tomcat2中加入
<Context docBase="/opt/tomcat1/webapps/ROOT" path="" reloadable="true">
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:localhost:11211,n2:localhost:11311"
failoverNodes="n2"
sticky="false"
requestUriIgnorePattern=".*\.(png|gif|jpg|css|js)$"
sessionBackupAsync="false"
sessionBackupTimeout="100"
ranscoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory" copyCollectionsForSerialization="false" />
</Context>
4.当tomcat1设置过期时间是10s tomcat2设置过期时间是20s
在登录的时候通过tomcat1访问,登录进入后没有操作10s过期,当通过tomcat2访问,登录无操作20S过期
当登录tomcat后对网站进行操作,过期的时间是根据操作停止后,登录时的tomcat配置的过期时间。