Apache2+Tomcat6负载均衡

来源:互联网 发布:linux 压缩效率 编辑:程序博客网 时间:2024/06/04 18:00

ApacheTomcat集群,负载均衡

 

1软件列表

·apache_2.2.4-win32-x86-no_ssl.msi

·tomcat6.0

·mod_jk-1.2.26-httpd-2.2.4.so

 

2安装方法

      ·编辑系统配置文件WINDOWS/system32/drivers/etc/hosts,追加一行:127.0.0.1  localhost

      · tomcat的连接文件mod_jk-1.2.26-httpd-2.2.4.so复制到Apache安装目录下的modulers目录下

      ·编辑Apache配置文件conf/httpd.conf

在文件尾部追加内容:

           LoadModule jk_modulemodules/mod_jk-1.2.26-httpd-2.2.4.so

JkWorkersFileconf/workers.properties

JkMount /* lbcontroller

      ·在Apache安装目录下的conf目录下,新建workers.properties文件,编辑内容如下:

#分发控制器,lbcontroller值对应conf/httpd.conf中的JkMount /* lbcontroller

 

worker.list=lbcontroller

 

######Tomcat1实例配置#####

#tomcat1,对应tomcatserver.xml <Enginename="tomcat1" defaultHost="localhost"jvmRoute="tomcat1">jvmRoute

#host值对应server.xml中的<Hostname="localhost" appBase="webapps">以及hosts文件中的值

worker.tomcat1.host=localhost

 

#port值对应server.xml中的节点<Connectorport="8010" protocol="AJP/1.3"redirectPort="8443" />

worker.tomcat1.port=8010

 

worker.tomcat1.type=ajp13

#分发权重,值越大负载越大

worker.tomcat1.lbfactor=1

 

#Tomcat2实例配置

worker.tomcat2.host=localhost

worker.tomcat2.port=8011

worker.tomcat2.type=ajp13

worker.tomcat2.lbfactor=1

 

#负载均衡分发控制器

worker.lbcontroller.type=lb

worker.lbcontroller.balance_workers=tomcat1,tomcat2

worker.lbcontroller.sticky_session=1

 

 

 

·修改各个tomcat配置文件server.xml,保持各端口相异

<Server port="8006"shutdown="SHUTDOWN">

<Connectorport="8001" protocol="HTTP/1.1"

              connectionTimeout="20000"

               redirectPort="8443"URIEncoding="UTF-8"/>

<Connectorport="8010" protocol="AJP/1.3"redirectPort="8443" />

<Engine name="tomcat1"defaultHost="localhost" jvmRoute="tomcat1">

 

<Hostname="localhost" appBase="webapps"

            unpackWARs="true"  autoDeploy="true"

           xmlValidation="false" xmlNamespaceAware="false">

 

增加或从注释中释放以下两个节点:

1<ValveclassName="org.apache.catalina.valves.RequestDumperValve"/>

2<ClusterclassName="org.apache.catalina.ha.tcp.SimpleTcpCluster" 

          channelSendOptions="8">  

          <ManagerclassName="org.apache.catalina.ha.session.DeltaManager" 

                  expireSessionsOnShutdown="false" 

                  notifyListenersOnReplication="true"/>  

          <ChannelclassName="org.apache.catalina.tribes.group.GroupChannel">  

            <MembershipclassName="org.apache.catalina.tribes.membership.McastService" 

                       address="228.0.0.4" 

                       port="45564" 

                       frequency="500" 

                       dropTime="3000"/>  

            <ReceiverclassName="org.apache.catalina.tribes.transport.nio.NioReceiver" 

                     address="auto" 

                     port="4000" 

                     autoBind="100" 

                     selectorTimeout="5000" 

                     maxThreads="6"/>  

            <!--timeout="60000"-->  

            <SenderclassName="org.apache.catalina.tribes.transport.ReplicationTransmitter">  

              <TransportclassName="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>  

           </Sender>  

            <InterceptorclassName="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>  

            <InterceptorclassName="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>  

            <InterceptorclassName="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>  

         </Channel>

          <ValveclassName="org.apache.catalina.ha.tcp.ReplicationValve" 

                 filter=""/>  

          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>  

          <DeployerclassName="org.apache.catalina.ha.deploy.FarmWarDeployer" 

                   tempDir="/tmp/war-temp/" 

                   deployDir="/tmp/war-deploy/" 

                    watchDir="/tmp/war-listen/" 

                   watchEnabled="false"/>  

<ClusterListenerclassName="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>  

<ClusterListenerclassName="org.apache.catalina.ha.session.ClusterSessionListener"/>

 </Cluster>

 

 

如果需要实现session 复制 需要在web.xml 中加上<distributable/>

<?xmlversion="1.0" encoding="ISO-8859-1"?>

   <welcome-file-list>

       <welcome-file>index.html</welcome-file>

       <welcome-file>index.htm</welcome-file>

        <welcome-file>index.jsp</welcome-file>

   </welcome-file-list>

<distributable/>

</web-app>

 

说明:

web系统发布至各个tomcatwebapp

通过localhost/myweb即可访问

原创粉丝点击