1. 环境
JDK : jdk1.6.0.39
Tomcat: apache-tomcat-6.0.43-windows-x64.zip
Apache: httpd-2.2.17-win32-x86-no_ssl.msi
2. Apache 更改
http.conf: 路径D:\jiqun\Apache2.2\conf
去掉一下注释:
Include conf/extra/httpd-vhosts.conf
LoadModule negotiation_module modules/mod_negotiation.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
LoadModule proxy_http_module modules/mod_proxy_http.so
在文件末尾加上
ProxyRequests Off
BalancerMember ajp://127.0.0.1:18009 loadfactor=1 route=worker1
BalancerMember ajp://127.0.0.1:28009 loadfactor=1 route=worker2
说明:ajp://127.0.0.1:18009中18009是
httpd-vhosts.conf: 路径D:\jiqun\Apache2.2\conf\extra
ServerName192.168.191.1#本机IP地址
ServerAlias localhost
ProxyPass /balancer://loadbalancer/ stickysession=jsessionid nofailover=On
ProxyPassReverse /balancer://loadbalancer/
ErrorLog"logs/loadbalancer-error.log"
CustomLog"logs/loadbalancer-access.log" common
3. tomcat更改
我是在同一台机器上安装的集群所以tomcat中所有端口不可以一致(不同机器不用更改)
connectionTimeout="20000"
redirectPort="8443" />
端口改了
将
在webapp中创建test文件夹,在创建test.jsp
Test.jsp 内容:<html>
<head>
<title>helloapptitle>
head>
<body>
<%
System.out.println("call test.jsp");
%>
SessionID: <%=session.getId() %>
body>
html>
复制到第二个tomcat中
启动两个tomcat访问
http://localhost:18080/test/test.jsp
http://localhost:28080/test/test.jsp
出现以下东西说明tomcat没有问题
SessionID: B433DBAB83AABD1E71023F7E129EA753.worker1
SessionID: B433DBAB83AABD1E71023F7E129EA753.worker2
在启动apache
访问:http://127.0.0.1/test/test.jsp
出现以下东西多次访问SessionID是同一个说明连接集群搭建成功
SessionID: B433DBAB83AABD1E71023F7E129EA753.worker1
SessionID: B433DBAB83AABD1E71023F7E129EA753.worker2
文档写的有些粗超,希望能给大家带来一些思路,如有不懂请加qq群:58912623