windows下使用apache搭建tomcat集群

1.软件清单:

 (1)Apache HTTP server2.4_X64

 (2)Tomcat7_X64 

 (3)mod_jk_2.0.46.so

安装apache,安装完成后如下图所示:


mod_jk.so拷到modules目录下面

修改apache配置文件 http.conf

在apache安装目录下conf目录中找到http.conf,更改 ServerName127.0.0.1:80

并且在文件最后加上下面一句话就可以了

include conf/mod_jk.conf

http.conf 同目录下,创建 mod_jk.conf 文件,内容如下:

#加载 mod_jk.so 模块

LoadModule jk_module modules/mod_jk.so

#加载mod_jk.so 配置文件

JkWorkersFile conf/workers.properties

#指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器 ( 比如制定 jsp 文件:JkMount /*.jspcontroller )

JkMount /* controller(分流所有请求)

http.conf 同目录下,创建workers.properties文件 ,内容如下:

#===server 列表
worker.list = controller,tomcat1,tomcat2
#========tomcat1 需要注意此名字对应tomcat中server.xml <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1"> ========
#==ajp13端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.port=8009(apj端口号)
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
#server的加权比重,值越高,分得的请求越多
worker.tomcat1.lbfactor=1
# 给worker1定义了一个发生错误处理失败后要引用的节点
worker.tomcat1.redirect= tomcat2
# worker “worker2″ 用掉10个套接字, 这些会保持不超过10钟的缓存
worker.tomcat1.cachesize=10
worker.tomcat1.cache_timeout=600
# worker “tomcat1″ 会请求操作系统给连接(connection)发出 KEEP-ALIVE 信号
worker.tomcat1.socket_keepalive=1
# worker “tomcat1″ 试图使ajp13 连接于5分钟后断开(周期性的)
worker.tomcat1.recycle_timeout=300

#========tomcat2========
worker.tomcat2.port=8209(apj端口号)
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
# 除非发生了错误并且处理失败了,否则就禁用所有发给worker2的请求
worker.tomcat2.disabled=True
# worker “tomcat2″ 用掉10个套接字, 这些会保持不超过10钟的缓存
worker.tomcat2.cachesize=10
worker.tomcat2.cache_timeout=600
# worker “tomcat2″ 会请求操作系统给连接(connection)发出 KEEP-ALIVE 信号
worker.tomcat2.socket_keepalive=1
# worker “tomcat2″ 试图使ajp13 连接于5分钟后断开(周期性的)
worker.tomcat2.recycle_timeout=300

#========controller========
worker.controller.type=lb
#指定分担请求的tomcat
worker.controller.balance_workers=tomcat1,tomcat2
worker.controller.sticky_session=1
修改tomcat1/conf/server.xml文件
<Server port="8005" shutdown="SHUTDOWN">
  <Connector port="8081" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

修改tomcat2/conf/server.xml文件

<Server port="8205" shutdown="SHUTDOWN">
<Connector port="8082" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8444" />
<Connector port="8209" protocol="AJP/1.3" redirectPort="8444" />
  <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomact2">

修改tomcat1, tomcat2server.xml,将集群部分配置:

<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"
                        address="228.0.0.4"
                        port="45564"
                        frequency="500"
                        dropTime="3000"/>
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                      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=".*\.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>

WEB-INF下的web.xml中添加

<distributable />
完成集群的搭建


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值