1. 下载软件:
1.1 web http server: httpd-2.2.15-win32-x86-no_ssl.msi
下载地址: http://archive.apache.org/dist/httpd/binaries/win32/httpd-2.2.15-win32-x86-no_ssl.msi
其它各个版本:http://archive.apache.org/dist/httpd/binaries/win32/
1.2 tomcat:apache-tomcat-6.0.26.zip
下载地址:http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.26/bin/apache-tomcat-6.0.26.zip
其它各个版本:http://archive.apache.org/dist/tomcat/
2. 安装软件
安装httpd-2.2.15-win32-x86-no_ssl.msi ,
我的目录是:D:\LoadBalance\apache\Apache2.2
apache-tomcat-6.0.26.zip 解压即可
3. 配置
3.1. 配置apache server 找到D:\LoadBalance\apache\Apache2.2\conf\httpd.conf 配置文件:
a. 简单的把下面几行去掉注释,就相当于以前用mod_jk.so比较繁琐的配置了。这里 主要采用了代理的方法,就这么简单。
LoadModule proxy_module modules/mod_proxy.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
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
b. 再找到<IfModule dir_module></IfModule>加上index.jsp修改成如下:
<IfModule dir_module>
DirectoryIndex index.html index.jsp
</IfModule>
c. 在最下面加入
# new add config===========================================================
ProxyRequests Off
<proxy balancer://cluster>
BalancerMember ajp://127.0.0.1:8019 loadfactor=1 route=jvm1
BalancerMember ajp://127.0.0.1:8029 loadfactor=1 route=jvm2
BalancerMember ajp://127.0.0.1:8039 loadfactor=1 route=jvm3
BalancerMember ajp://127.0.0.1:8049 loadfactor=1 route=jvm4
BalancerMember ajp://127.0.0.1:8059 loadfactor=1 route=jvm5
</proxy>
3.2. 找到D:\LoadBalance\apache\Apache2.2\conf\extra\httpd-vhosts.conf 配置文件:
先删掉以下配置:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "D:/LoadBalance/apache/Apache2.2/docs/dummy-host.localhost"
ServerName dummy-host.localhost
ServerAlias www.dummy-host.localhost
ErrorLog "logs/dummy-host.localhost-error.log"
CustomLog "logs/dummy-host.localhost-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "D:/LoadBalance/apache/Apache2.2/docs/dummy-host2.localhost"
ServerName dummy-host2.localhost
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" common
</VirtualHost>
重新添加以下内容:
# new add config ==================================================================
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName localhost
ServerAlias localhost
ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On
ProxyPassReverse / balancer://cluster/
</VirtualHost>
3.3 现在开始配置Tomcat ,找到配置文件 :D:\LoadBalance\tomcat_6_1\conf\server.xml
3.3.1 先修改以下内容:
原内容为:<Server port="8005" shutdown="SHUTDOWN">
修改后为:<Server port="8015" shutdown="SHUTDOWN">
-------其它 tomcat 将 port设置为: 8025 ,8035, 8045 , 8055 (对应:tomcat_6_2,tomcat_6_3,tomcat_6_4,tomcat_6_5)
3.3.2 修改以下内容:
原内容为:
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
修改后为:
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8019" protocol="AJP/1.3" redirectPort="8413" />
-------其它 tomcat 将 port 设置为: 8029 ,8039, 8049 , 8059 redirectPort: 8423, 8433 ,8443 , 8453
---------- (对 应:tomcat_6_2,tomcat_6_3,tomcat_6_4,tomcat_6_5)
3.3.3 修改以下内容:
先注释掉以下内容:
<Engine name="Catalina" defaultHost="localhost">
原内容为:
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
修改后为:
<!-- You should set jvmRoute to support load-balancing via AJP ie : -->
<Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">
----其它tomcat 设置: jvmRoute 为: jvm2, jvm3, jvm4, jvm5 (对 应:tomcat_6_2,tomcat_6_3,tomcat_6_4,tomcat_6_5)
------还记得上面3.1.c 的设置吗?
3.3.4 修改以下内容:
原内容为:
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
修改后为:
<Receiver port="9091"/>
<!--
---- 其它tomcat 的 Receiver port 设置: 9092 , 9093 , 9094 , 9095 (对 应:tomcat_6_2,tomcat_6_3,tomcat_6_4,tomcat_6_5)
--->
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6">
<Manager className="org.apache.catalina.ha.session.BackupManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true" mapSendOptions="6"/>
<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;"/>
<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.ClusterSessionListener"/>
</Cluster>
配置已完成!
tomcat_6_2,3,4,5 怎样配置,你应该知道了吧?
4. 测试
4.1 现在可以将 test.war 分别放入 各个tomcat 中的 \webapps 目录下面:
先启动各个tomcat , 再启动apache http 服务器!
4.2 打开一个browser ,输入: http://localhost/test/index.jsp 留意各个tomcat 的控制台输出的信息。