Apache 2+Tomcat 6+JK配置服务器集群

Step1.下载Apache 2+Tomcat 6+JK免安装版本【注:jdk配置JAVA_HOME】

step2.Apache配置

httpd.conf:

#Listen 12.34.56.78:80
Listen 80 #监听端口号
# (httpd.conf)
# 加载 mod_jk 模块
LoadModule jk_module modules/mod_jk-1.2.31-httpd-2.2.3.so
# Configure mod_jk
JkWorkersFile conf/workers.properties
JkMountFile conf/uriworkermap.properties
JkLogFile logs/mod_jk.log
JkLogLevel warn
#Admin  allen 123
<Location /jkstatus>
Order deny,allow
AuthType Basic
AuthName "Auther Center"
AuthUserFile conf/passwd
require valid-user
</Location>

Apache2 手动添加配置文件:
(1)workers.properties
(2)uriworkermap.properties

详细配置如下:

# workers.properties
# list the workers by name
worker.list=controller, status
# localhost server 1
# ----------tomcat1-------------
worker.tomcat1.port=11009
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1
#worker.tomcat2.stopped=1
# localhost server 2
# -----------tomcat2------------
worker.tomcat2.port=12009
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13
worker.tomcat1.lbfactor=1
#worker.tomcat2.stopped=1
#-----controller 负载均衡控制器-----
worker.controller.type=lb
#worker.retries=3
worker.controller.balanced_workers=tomcat1,tomcat2
worker.controller.sticky_session=false
worker.controller.sticky_session_force=1
#worker.controller.sticky_session=1
worker.status.type=status
uriworkermap.properties
/*=controller
/jkstatus=status
!/*.gif=controller
!/*.jpg=controller
!/*.png=controller
!/*.css=controller
!/*.js=controller
!/*.htm=controller
!/*.html=controller
Tomcat  server.xml配置:<!-- Define an AJP 1.3 Connector on port 8009 -->
   
<Connector port="11009" protocol="AJP/1.3" redirectPort="8443" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">         
    -->
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
     <!--
     <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
     -->
      <!--配置集群-->
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"  channelSendOptions="8">     

                  <Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true"/>
                  <!--<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="5002" 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"/>   
                  <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;"/>    

                  <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>

             
      <!-- The request dumper valve dumps useful debugging information about
           the request and response data received and sent by Tomcat.
           Documentation at: /docs/config/valve.html -->
      <!--
      <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
      -->

      <!-- This Realm uses the UserDatabase configured in the global JNDI
           resources under the key "UserDatabase".  Any edits
           that are performed against this UserDatabase are immediately
           available for use by the Realm.  -->
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>

      <!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.配置虚拟主机 一个tomcat运行多个项目
        -->
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
               prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
        -->

      </Host>
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">

  

      </Host>



Tomcat  webapp web.xml配置:

<distributable/>

注意事项:1.AJP协议端口冲突 2.jk权限认证

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值