tomcat集群--整合Apache服务器,采用mod_JK连接模式

一、集群技术初步分析

1、tomcat集群多应用服务器,分担压力,并保证服务高可用,使用tomcat自带cluster实现集群环境,Manager负责管理session共享
2、web服务器采用Apache,负责应用服务器间负载均衡
3、apache服务器和tomcat的连接方法其实有三种:mod_JK、http_proxy和ajp_proxy,本文采用mod_JK模式
4、盗一张图,如下:
这里写图片描述

二、tomcat集群环境安装与配置

1、下载tomcat服务器,本文使用apache-tomcat-7.0.64版本,复制两份,分别为tomcat1和tomcat2,配置server.xml,以tomcat1为例,配置代码如下:

<!-- 服务关闭端口 -->
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JasperListener" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!-- http连接器使用nio非阻塞模式,Excutor作为执行器提供线程池支持 -->
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="10"/>

    <!-- 负责建立HTTP连接,使用nio非阻塞模式,配置使用executor执行器,使用连接池 -->
    <Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
               connectionTimeout="20000"
               redirectPort="8443" 
           executor="tomcatThreadPool"/>

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <!-- AJP连接器,监听8009端口,采用AJP协议,连接tomcat服务器与http服务器(如Apache服务器),实现两者通信 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <!-- 使用AJP协议实现负载均衡,需要jvmRoute参数,值自定义
         Tomcat会在创建session时会根据根据jvmRoute的值在sessionID后面追加route值
         用于追踪分发的请求
    -->
    <Engine name="Catalina" defaultHost="localhost"  jvmRoute="tomcat1">

    <!-- Clus
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值