<转载>--配置Apache+JK2+Tomcat集群与负载均衡
(摘抄自《Java Web 2.0架构开发与项目实战》一书)
首先从Apache网站http://httpd.apache.org/download.cgi上下载wingdows安装版本的apache_2.2.11-win32-x86-no_ssl.msi,然后根据安装向导安装该服务器.Apache服务器默认使用80端口.
从Apache网站http://tomcat.apache.org/connnectors-doc/下载连接器mod_jk-1.2.27-httpd-2.2.10.so,这个文件的版本要与Apache版本相同,目标都是2.2版本的.然后将这个.so文件放入Apache安装目录下的modules目录中,并更改Apache服务器中的httpd.conf,在conf目录中可以找到该文件,在文件最后加上下面一行代码:
include "E:\Apache2\conf\mod_jk.conf" # E:Apache2是Apache的安装目录
worker.list=controller,tomcat1,tomcat2 #server 列表 #============tomcat1============ worker.tomcat1.prot=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 worker.tomcat2.host=localhost worker.tomcat2.type=ajp13 worker.tomcat2.lbfactor=1 #===========controller,负载均衡控制器========== worker.controller.type=lb worker.controller.balanced_workers=tomcat1,tomcat2 #指定分担请求的tomcat worker.controller.sticky_session=1
#加载mod_jk Module LoadModule jk_module modules/ mod_jk-1.2.27.10.so #指定workers.properties文件路径 JkWorkersFile conf/workers.properties #指定哪些请求交给tomcat处理,"controller"为在 workers.properties里指定的负载分配控制器 JkMount /*.jsp controller
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6"> <Manager className="org.apache.catalina.ha.session.BackupManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true" mapSentOptions="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" autoBind="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;.*\.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>