首页 > 代码库 > tomcat-msm-memcached
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
二,创建目录和测试页面在1和2节点上
在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
在1,2节点里。进入/usr/local/tomcat/conf编辑配置文件
vim server.xml
在 <Hostname="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">下添加以下内容
<Contextpath="/test" docBase="test">
</Context>
加上test后照样访问
然后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/
表明两个节点都可以访问
本文出自 “Linux” 博客,转载请与作者联系!
tomcat-msm-memcached