码迷,mamicode.com
首页 > 其他好文 > 详细

tomcat-msm-memcached

时间:2014-10-05 03:33:08      阅读:363      评论:0      收藏:0      [点我收藏+]

标签:tomcat-msm-memcached

环境准备

Tomcat+msm+memcached

俩个节点

1 ,172.16.31.1    tomcat

2 ,172.16.31.31   tomcat +memcached

3, 172.16.31.32  memcached

  

1 安装tomcat

安装包为apache-tomcat-7.0.55.tar.gz

tar xf apache-tomcat-7.0.55.tar.gz  -C /usr/local/

vim /etc/profile.d/tomcat.sh

export CATALINA_HOME=/usr/local/tomcat

export PATH=$CATALINA_HOME/bin:$PATH

 

cd /usr/local/  

ln -sv apache-tomcat-7.0.55/ tomcat

 

[root@localhost ~]# ss -tnl

State      Recv-Q Send-Q                    Local Address:Port                      Peer Address:Port

LISTEN     0      128                                   :::111                                  :::*    

LISTEN     0      128                                    *:111                                   *:*    

LISTEN      0     100                                  :::8080                                :::


2,编辑配置文件

vim /etc/httpd/conf.d/mod_proxy.con
 
<Proxy balancer://lbcluster1>
      BalancerMember ajp://172.16.31.1:8009 loadfactor=1 route=TomcatA
      BalancerMember ajp://172.16.31.31:8009 loadfactor=1 route=TomcatB
      ProxySet lbmethod=byrequests
</Proxy>
<Location /status>
       SetHandler balancer-manager
       ProxyPass !
       Order allow,deny
       Allow from all
</Location>
ProxyPass / balancer://lbcluster1/
ProxyPassReverse / balancer://lbcluser1

2 然后再主机2中启动memcached


# service memcached restart

ss -tnl

State      Recv-Q Send-Q                    Local Address:Port                      Peer Address:Port

LISTEN     0      128                                    :::11211                                :::*    

LISTEN     0      128                                   *:11211 

 

3 然后再3中安装memcached

yum -y install memcached



二,创建目录和测试页面在12节点上

cd /usr/local/tomcat/webapps/

mkdir -pv test/WEB-INF/{classes,lib}

1节点上 vimtest/index.jsp

<%@ page language="java" %>
<html>
 <head><title>TomcatA</title></head>
 <body>
   <h1><fontcolor="red">TomcatA.magedu.com</font></h1>
   <table 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>

2节点上vim test/index.jsp

<%@ page language="java" %>
<html>
 <head><title>TomcatB</title></head>
 <body>
   <h1><fontcolor="blue">TomcatB.magedu.com</font></h1>
   <table 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>

 

然后1,2节点上重启服务

# service tomcat restar


bubuko.com,布布扣

bubuko.com,布布扣



1,2节点里。进入/usr/local/tomcat/conf编辑配置文件

vim server.xml

     <Hostname="localhost" appBase="webapps"

           unpackWARs="true" autoDeploy="true">下添加以下内容

          

<Contextpath="/test" docBase="test">

           </Context>

 

加上test后照样访问


bubuko.com,布布扣

bubuko.com,布布扣



然后1,2上配置文件中再加一段内容

<Host name="localhost"  appBase="webapps"
           unpackWARs="true" autoDeploy="true">
 
        <Context path="/test" docBase="test">
         <ManagerclassName="de.javakaffee.web.msm.MemcachedBackupSessionManager"
               memcachedNodes="n1:172.16.31.32:11211,n2:172.16.31.31:11211"
              failoverNodes="n1"              requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"     transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"
           />
                       </Context>

1,2 节点上,然后把五个类放入文件中

[root@localhost ~]# cd msm/

[root@localhost msm]# ls

javolution-5.5.1.jar                memcached-session-manager-tc7-1.8.2.jar spymemcached-2.10.2.jar

memcached-session-manager-1.8.2.jar  msm-javolution-serializer-1.8.2.jar

[root@localhost msm]# cp */usr/local/tomcat/lib/

bubuko.com,布布扣

bubuko.com,布布扣

表明两个节点都可以访问


本文出自 “Linux” 博客,转载请与作者联系!

tomcat-msm-memcached

标签:tomcat-msm-memcached

原文地址:http://clarence.blog.51cto.com/8161461/1560634

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