参考网址:http://www.cnblogs.com/onlywujun/articles/2913949.html
apache版本2.2 tomcat6
本文主要包括以下内容:
Ø Apache的配置
Ø Tomcat的配置
首先在apache 的conf目录下找到httpd.conf(apache 的配置文件)文件
在该文件里找到
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
并且把上面的#号去掉。
然后找到
Include conf/extra/httpd-vhosts.conf
把上面的#号去掉。
配置session粘性只需要在httpd.conf里最后一段加上如下信息(ajp://127.0.0.1:8010的8010配置的是tomcat的ajp端口,route=tomcat3中的tomcat3是tomcat配置文件server.xml里的jvmRoute的值):
ProxyRequests Off
ProxyPass / balancer://cluster/ lbmethod=byrequests stickysession=JSESSIONID nofailover=Off timeout=5 maxattempts=3
ProxyPassReverse / balancer://cluster/
<proxy balancer://cluster>
BalancerMember ajp://127.0.0.1:8010 loadfactor=1 route=tomcat3
BalancerMember ajp://127.0.0.1:8020 loadfactor=1 route=tomcat2
</proxy>
第二步找到\conf\extra包下面的httpd-vhosts.conf
在下面加上
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName localhost
ServerAlias localhost
ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On
ProxyPassReverse / balancer://cluster/
ErrorLog "logs/dummy-host2.163.com-error.log"
CustomLog "logs/dummy-host2.163.com-access.log" common
</VirtualHost>
第三步找到解压后的tomcat在不同的tomcat里修改server.xml里的端口参数使之不重复
(大家都知道就不详细说了)
这里改几个比较重要的参数
一个是<Engine name="Catalina" defaultHost="localhost">
改成<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">
另一个后面改成tomcat3
每个tomcat都加上:
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="8">
<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"
mcastBindAddress="127.0.0.1"
address="228.0.0.4"
port="45564"
frequency="500"
dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
tcpListenAddress="127.0.0.1"
address="auto"
port="4000"
autoBind="100"
selectorTimeout="5000"
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"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=""/>
<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>