发布时间:2014-09-05 16:43:10作者:知识屋
系统环境:Windows XP SP3 ,jdk1.6.0_13
软件版本:httpd-2.2.21-win32-x86-openssl-0.9.8r.msi apache-tomcat-6.0.33 tomcat-connectors-1.2.32-windows-i386-
httpd-2.2.x
我是在一台机器上作的测试,因为我完成了apache的负载均衡以及tomcat6的集群和session的复制,
需要修改到的地方可能比较多,先将配置列出如下:
1. 修改apache的httpd.conf:
首先要load所需要的so文件,把下面几行前面的注释去掉.
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
加入load连接器的配置
LoadModule jk_module modules/mod_jk.so
JkWorkersFile "conf/workers.properties"
JkMount /*.jsp controller
去掉虚拟主机的注释
Include conf/extra/httpd-vhosts.conf
结尾加上负载均衡配置
<Location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from all
</Location>
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Deny from all
Allow from all
</Location>
ProxyRequests Off
ProxyPass /test balancer://tomcatcluster/ stickysession=jsessionid nofailover=On
<Proxy balancer://tomcatcluster>
BalancerMember ajp://127.0.0.1:8009 loadfactor=1 route=tomcat1
BalancerMember ajp://127.0.0.1:9009 loadfactor=1 route=tomcat2
</Proxy>
2. apache的httpd-vhosts.conf文件中加入:
<VirtualHost *:80>
ServerAdmin webmaster@163.com
ServerName localhost
ServerAlias localhost
ProxyPass / balancer://tomcatcluster/ stickysession=jsessionid nofailover=On
ProxyPassReverse / balancer://tomcatcluster/
</VirtualHost>
3.创建workers.properties文件
#========tomcat1========
worker.tomcat1.port=8009 #ajp13 端口号,在tomcat下server.xml配 置,默认8009
worker.tomcat1.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
#========tomcat2========
worker.tomcat2.port=9009 #ajp13 端口号,在tomcat下server.xml配置,
worker.tomcat2.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
#========controller,负载均衡控制器========
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2 #指定分担请求的tomcat
worker.controller.sticky_session=false #worker.controller.sticky_session=1
4.修改tomcat的server.xml:
除了把两个tomcat冲突的端口都改掉,还需要加入下的集群设置
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1"> --另一个为tomcat2
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6">
<!--
<Manager className="org.apache.catalina.ha.session.BackupManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"
mapSendOptions="6"/>
-->
<Manager className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
port="45564"
frequency="500"
dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="5001"
selectorTimeout="100"
maxThreads="6"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=".*/.gif;.*/.js;.*/.jpg;.*/.png;.*/.htm;.*/.html;.*/.css;.*/.txt;"/>
<!--
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
-->
<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
<!--
<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
-->
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
5.webapps应用下web.xml配置
Webapps目录下的应用程序的web.xm中必须添加
<distributable/> 此应用将与群集服务器复制Session
配置完成,先启动所有tomcat服务器,最后启动apache2.2服务器.
6.下面jsp可以作为测试程序部署在tomcat1,tomcat2
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.util.*" %>
<html><head><title>Cluster App Test</title></head>
<body>
Server Info:
<%
out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"<br>");%>
<%
out.println("<br> ID " + session.getId()+"<br>");
String dataName = request.getParameter("dataName");
if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter("dataValue");
session.setAttribute(dataName, dataValue);
}
out.print("<b>Session 列表</b>");
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
out.println( name + " = " + value+"<br>");
System.out.println( name + " = " + value);
}
%>
<form action="index.jsp" method="POST">
名称:<input type=text size=20 name="dataName">
<br>
值:<input type=text size=20 name="dataValue">
<br>
<input type=submit>
</form>
</body>
</html>
成功配置的结果是tomcat1,tomcat2的后台打印session内容相同,通过apache访问请求被分发
摘自我行我诉
linux一键安装web环境全攻略 在linux系统中怎么一键安装web环境方法
Linux网络基本网络配置方法介绍 如何配置Linux系统的网络方法
Linux下DNS服务器搭建详解 Linux下搭建DNS服务器和配置文件
对Linux进行详细的性能监控的方法 Linux 系统性能监控命令详解
linux系统root密码忘了怎么办 linux忘记root密码后找回密码的方法
Linux基本命令有哪些 Linux系统常用操作命令有哪些
Linux必学的网络操作命令 linux网络操作相关命令汇总
linux系统从入侵到提权的详细过程 linux入侵提权服务器方法技巧
linux系统怎么用命令切换用户登录 Linux切换用户的命令是什么
在linux中添加普通新用户登录 如何在Linux中添加一个新的用户
2012-07-10
CentOS 6.3安装(详细图解教程)
Linux怎么查看网卡驱动?Linux下查看网卡的驱动程序
centos修改主机名命令
Ubuntu或UbuntuKyKin14.04Unity桌面风格与Gnome桌面风格的切换
FEDORA 17中设置TIGERVNC远程访问
StartOS 5.0相关介绍,新型的Linux系统!
解决vSphere Client登录linux版vCenter失败
LINUX最新提权 Exploits Linux Kernel <= 2.6.37
nginx在网站中的7层转发功能