码迷,mamicode.com
首页 > 系统相关 > 详细

LNMP之memcached实现tomcat群集(三)

时间:2015-09-16 23:42:21      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:

1、  安装依赖包

yum install libevent libevent-devel

2、  安装memcached

tar zxf memcached-1.4.24.tar.gz

cd memcached-1.4.24

./configure

make

 make install

查看安装是否成功:ls-al /usr/local/bin/mem*

3、  启动及关闭memcached

/usr/local/bin/memcached -d -m 10 -u root -l localhost -p 11211-c 256 -P /tmp/memcached.pid

 

测试启动是否成功:
telnet localhost 11211

 

关闭memcached:

kill `cat /tmp/memcached.pid`

 

4、  MemcachedTomcat配置(session同步)

首先,将之前下载的JAR包全部拷贝到Tomcatlib

接着,配置两个Tomcatcontext.xml的文件:在Context标签内加入如下内容:

<ManagerclassName="de.javakaffee.web.msm.MemcachedBackupSessionManager"        

       memcachedNodes="n1:localhost:11211"

       requestUriIgnorePattern=".*/.(png|gif|jpg|css|js)$"

        sessionBackupAsync="false"

       sessionBackupTimeout="100"

transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"

       copyCollectionsForSerialization="false"/>

 

5、  修改tomcat默认目录及主页:

server.xml的标签</Host>  上面添加 <Contextpath="" docBase="../webapps/test1" debug="0"reloadable="true" />

 

index.jsp内容:
  <%@ page language="java"contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>

<html>

<body>

SessionID:<%=session.getId()%>

<BR>

SessionIP:<%=request.getServerName()%>

<BR>

SessionPort:<%=request.getServerPort()%>

<%

out.println("Itis test1");           

%>

<%=(String)session.getAttribute("user")%>

</body>

</html>

 


6、  Memcached自启动:

vi /etc/rc.d/rc.local

在最后添加:

/usr/local/bin/memcached -d -m 10 -u root -l localhost -p11211 -c 256 -P /tmp/memcached.pid


本文出自 “IT梦工厂” 博客,请务必保留此出处http://fly520.blog.51cto.com/2181586/1695462

LNMP之memcached实现tomcat群集(三)

标签:

原文地址:http://fly520.blog.51cto.com/2181586/1695462

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!