一、拓扑图
二、环境安装
安装memcached的直接yum
[root@70sec ~]# yum -y install memcached
[root@70sec ~]# service memcached start
Starting memcached: [ OK ]
[root@70sec ~]# ss -anlpt | grep memcached
LISTEN 0 128 :::11211 :::* users:(("memcached",26347,27))
LISTEN 0 128 *:11211 *:* users:(("memcached",26347,26))
[root@70sec ~]#
因为tomcat依赖于java环境 所以先安装jdk,(tomcat A B 都相同)
[root@90sec src]# rpm -ivh jdk-7u9-linux-x64.rpm
[root@90sec src]# vim /etc/profile.d/java.sh
JAVA_HOME=/usr/java/jdk1.7.0_09
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME
[root@90sec src]# source /etc/profile.d/java.sh
安装tomcat
[root@90sec src]# tar xf apache-tomcat-7.0.42.tar.gz -C /usr/local/
[root@90sec src]# cd /usr/local/
[root@90sec local]# ln -sv apache-tomcat-7.0.42/ tomcat
`tomcat' -> `apache-tomcat-7.0.42/'
[root@90sec tomcat]# vim /etc/profile.d/tomcat.sh
export CATALINA_HOME=/usr/local/tomcat
export PATH=$CATALINA_HOME/bin:$PATH
[root@90sec tomcat]# source /etc/profile.d/tomcat.sh
[root@90sec tomcat]# catalina.sh version #查看版本
[root@90sec tomcat]# catalina.sh start #启动
修改tomcat的配置文件(A和B相同)
配置Session共享Memcache,分别放在两个tomcat的lib下
javolution-5.4.3.1.jar
memcached-session-manager-1.8.1.jar
memcached-session-manager-tc7-1.8.1.jar z
msm-javolution-serializer-1.8.1.jar
spymemcached-2.10.2.jar
[root@90sec tomcat]# vim conf/context.xml
<Context>
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:192.168.83.134:11211"
failoverNodes="n1"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
</Context>
为tomcat提供测试页
#### tomcat A##########
[root@90sec tomcat]# mkdir -pv /usr/local/tomcat/webapps/test/WEB-INF/{classes,lib}
[root@90sec tomcat]# vim /usr/local/tomcat/webapps/test/index.jsp
<%@ page language="java" %>
<html>
<head><title>TomcatA</title></head>
<body>
<h1><font color="red">TomcatA.magedu.com</font></h1>
<table align="centre" 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>
~ #####tomcat B##########
mkdir -pv /usr/local/tomcat/webapps/test/WEB-INF/{classes,lib}
[root@80sec tomcat]# vim /usr/local/tomcat/webapps/test/index.jsp
<%@ page language="java" %>
<html>
<head><title>TomcatB</title></head>
<body>
<h1><font color="red">TomcatB.magedu.com</font></h1>
<table align="centre" 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>
安装httpd配置反代
[root@60sec ~]# yum -y install httpd
来源:oschina
链接:https://my.oschina.net/u/4377703/blog/4870818