Memcache+apache+tomcat
Client eth0:192.168.0.106
Apache eth0: 192.168.0.123
Tomcat1 eth0:192.168.0.120
Tomcat2 eth0:192.168.0.118.
Memcache主 eth0:192.168.0.115
Memcache eth0:192.168.0.110
部署apache
# yum install httpd httpd-devel
# echo “apache html test” >/var/www/html/index.html
# cd /tmp
# tar zxvftomcat-connectors-1.2.32-src.tar.gz
# cd tomcat-connectors-1.2.32-src/native
[root@localhost native]# ./configure --with-apxs=/usr/sbin/apxs #如果没有/usr/sbin/apxs需要安装httpd-devel
[root@localhost native]# make &&make install
[root@localhost native]# cp ../conf/httpd-jk.conf /etc/httpd/conf.d/jk.conf
[root@localhost native]# vim/etc/httpd/conf.d/jk.conf
JkMount /*.jsp wlb
[root@localhost native]# cp../conf/workers.properties /etc/httpd/conf
[root@localhost native]# vim/etc/httpd/conf/workers.properties
worker.list=wlb,jkstatus
worker.wlb.type=lb
worker.wlb.balance_workers=tomcat1,tomcat2
worker.tomcat1.type=ajp13
worker.tomcat1.host=192.168.0.120
worker.tomcat1.port=8009
worker.tomcat1.lbfactor=1
worker.tomcat2.type=ajp13
worker.tomcat2.host=192.168.0.119
worker.tomcat2.port=8009
worker.tomcat2.lbfactor=1
# service httpd start
部署 Tomcat 1 & Tomcat 2
# service httpd stop
# cd /tmp
# chmod +x jdk-6u27-linux-i586.bin
# ./jdk-6u27-linux-i586.bin
# mv jdk1.6.0_27/ /usr/local/jdk
# vim /etc/bashrc
export JAVA_HOME=/usr/local/jdk
export JAVA_BIN=/usr/local/jdk/bin/
export PATH=$JAVA_HOME/bin:$PATH
exportCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
# source /etc/bashrc
# java -version
# tar zxf apache-tomcat-6.0.32.tar.gz
# mv apache-tomcat-6.0.32 /usr/local/tomcat
# cd /usr/local/tomcat/bin
[root@localhost bin]# ./startup.sh
[root@localhost bin]# vim/usr/local/tomcat/webapps/ROOT/index.jsp 把自带的index.jsp删了
<html>
<bodybgcolor="red"> #Tomcat2 修改为别的颜色
<center>
<%=request.getSession().getId() %>
<h1>Tomcat1</h1> #Tomcat 2 改成2
</body>
</html>
# /usr/local/tomcat/bin/catalina.sh start 启动
# netstat �Ctnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0::ffff:127.0.0.1:8005 :::* LISTEN 2920/java
tcp 0 0 :::8009 :::* LISTEN 2920/java
tcp 0 0 :::8080 :::* LISTEN 2920/java
tcp 0 0 :::80 :::* LISTEN 2135/httpd
阶段测试
1.访问 index.html 由 Aapche 处理,
2.访问 index.jsp 交给 Tomcat 1 与 Tomcat 2 负载处理,
3.访问 index.jsp 时在 Tomcat 1 与 Tomcat 2 之间进行切换,但是 session_id 也随之变化
部署 Memcache 1 & Memcache 2
# tar xf libevent-2.0.15-stable.tar.gz
# cd libevent-2.0.15-stable
[root@localhost libevent-2.0.15-stable]#./configure && make && make install
# tar xf memcached-1.4.5.tar.gz
# cd memcached-1.4.5
[root@localhost memcached-1.4.5]#./configure && make && make install
# ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5
[root@localhost memcached-1.4.5]# memcached-h
[root@localhost memcached-1.4.5]# memcached-p 11211 -l 192.168.122.40 -u root -m 10 -c 10 -vvv -f 1.2 -n 60 打开监听
部署 Tomcat 1 & Tomcat 2 支持连接 Memcached
# cp session/*.jar /usr/local/tomcat/lib
# vim /usr/local/tomcat/conf/context.xml
<ManagerclassName="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:192.168.0.115:11211,n2:192.168.0.110:11211"
failoverNodes="n1"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
注意:定义内容要写在<Context></Context>里面
[root@localhost tmp]#/usr/local/tomcat/bin/shutdown.sh
[root@localhost tmp]# /usr/local/tomcat/bin/startup.sh
最终测试
1.访问 index.html 由 Aapche 处理,
2.访问 index.jsp 交给 Tomcat 1 与 Tomcat 2 负载处理,
3.访问 index.jsp 时在 Tomcat 1 与 Tomcat 2 之间进行切换,并且 session_id 不会变化
查看其它文档 下面有 百度云盘地址 软件包和文档都在里面 自行下载