由于安装apache2.2需要先安装arp和arp-util这两个东东所以也要从www.apache.org/dist上下载.
安装apr
# cd srclib/apr
# ./configure --prefix=/usr/local/apr
# make
# make install
安装apr-util
# cd ../apr-util/
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make
# make install
安装 apache(编译时加入ajp代理以及反向代理参数以及负载均衡参数)
#./configure --prefix=/usr/apache2.2 --enable-proxy --enable-proxy-ajp --enable-proxy-balancer --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
#make
#make install
#/usr/apache2.2/bin/apachectl –k start
apache安装成功以后需要对它的两个配置文件conf/httpd.conf和conf/extra/httpd-vhosts.conf做一点小小的修改。
在conf/httpd.conf文件里搜索一下“Include conf/extra/httpd-vhosts.conf”,把前面的“#”去掉。然后“conf/extra/httpd-vhosts.conf”文件修改如下:
<VirtualHost *:80>
ServerName localhost #服务器名称
CustomLog logs/dmim_log combined #日志
#负载均衡配置,可列出多个Tomcat;以下为连接Tomcat AJP监听器,
<Proxy balancer://localhost>
BalancerMember ajp://134.140.55.236:8009
BalancerMember ajp://134.140.55.236:9009
BalancerMember ajp://134.140.55.239:8009
</Proxy>
#代理配置
<Location />
ProxyPass balancer://localhost/
#ProxyPassReverse balancer://localhost/
</Location>
</VirtualHost>
Tomcat5.5自带集群功能,只要把server.xml中的“Cluster”元素注释掉就行了,并且在每个web应用项目的web.xml文件,添加<distributable/>元素。然后把tomcat复制几份到不同机器就行了(根据Tomcat官方文档描述一般配置2~4个作为集群,tomcat的配置要跟apache的负载均衡配置相对应);如果集群放在同一台机器上,要注意修改各个server.xml的以下元素: (红色的表示每个服务器配置的端口都不能一样,以免端口被占用)
<Server port="8005" shutdown="SHUTDOWN">
<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<Connector port="8009"
enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
<Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
managerClassName="org.apache.catalina.cluster.session.DeltaManager"
expireSessionsOnShutdown="false"
useDirtyFlag="true"
notifyListenersOnReplication="true">
<Membership
className="org.apache.catalina.cluster.mcast.McastService"
mcastAddr="228.0.0.4"
mcastPort="45564"
mcastFrequency="500"
mcastDropTime="3000"/>
<Receiver
className="org.apache.catalina.cluster.tcp.ReplicationListener"
tcpListenAddress="auto"
tcpListenPort="4001"
tcpSelectorTimeout="100"
tcpThreadCount="6"/>
<Sender
className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
replicationMode="pooled"
ackTimeout="15000"
waitForAck="true"/>
<Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>
<Deployer className="org.apache.catalina.cluster.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
<ClusterListener className="org.apache.catalina.cluster.session.ClusterSessionListener"/>
</Cluster>
最后重启apache和各个tomcat就行了
------------------------------------相关连接
http://www.ibm.com/developerworks/cn/opensource/os-lo-apache-tomcat/index.html
apache2.2和tomcat5.5 负载均衡配置
http://www.dlog.cn/html/diary/showlog.vm?sid=1564&log_id=10682