ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Apache httpd + tomcat 简单集群负载均衡配置

2022-09-07 18:30:27  阅读:320  来源: 互联网

标签:httpd tomcat worker conf jk Apache mod


目录

环境

Test on alfresco projects
httpd-2.4.25-win64-VC14.zip
apache-tomcat-6.0.48-windows-x64.zip
mod_jk-1.2.42-win64-VC14.zip

步骤

1. 使用集群,确保web.xml中一定要有<distributable/>

image

2. 对Tomcat的server.xml文件进行配置
  • 如果单机启动多个Tomcat。避免端口冲突,尽量配置每个Tomcat端口不一样
  • 修改Engine 节点,添加jvmRoute属性。值和apache httpd mod_jk 中的worker名字对应,必须样一样
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
......
</Engine>
  • server.xml文件中找到被注释掉的<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>在注释行的下面添加如下代码

摘自:http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html

<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=""/>
          <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>
3. 配置Apache httpd
1. 解压httpd-2.4.25-win64-VC14.zip
2. 修改配置文件Apache24/conf/httpd.conf
  • 配置ServerRoot
    ServerRoot "E:/My-Resources/Apache/httpd-2.4.25-win64-VC14/Apache24"
  • 配置Listen
    Listen 192.168.10.152:1314
  • 配置ServerName
    ServerName 192.168.10.152:1314
  • Directory添加allow from all
<Directory />
    AllowOverride none
    Require all denied
    allow from all
</Directory>
  • 配置DocumentRoot
DocumentRoot"E:/My-Resources/Apache/httpd-2.4.25-win64-VC14/Apache24/htdocs"

<Directory "E:/My-Resources/Apache/httpd-2.4.25-win64-VC14/Apache24/htdocs">

    #

    # Possible values for the Options directive are "None", "All",

    # or any combination of:

    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

    #

    # Note that "MultiViews" must be named *explicitly* --- "Options All"

    # doesn't give it to you.

    #

    # The Options directive is both complicated and important.  Please see

    # http://httpd.apache.org/docs/2.4/mod/core.html#options

    # for more information.

    #

    Options Indexes FollowSymLinks

 

    #

    # AllowOverride controls what directives may be placed in .htaccess files.

    # It can be "All", "None", or any combination of the keywords:

    #   AllowOverride FileInfo AuthConfig Limit

    #

    AllowOverride None

 

    #

    # Controls who can get stuff from this server.

    #

    Require all granted

</Directory>
3. 安装Apache httpd服务
  1. dos命令安装 httpd.exe -k install -n Apache
    image
  2. 启动服务,浏览器访问测试
    image
  3. httpd安装成功,关闭服务
4. 负载均衡配置
mod_jk配置
  • 解压mod_jk-1.2.42-win64-VC14.zip文件,把mod_jk.so放进Apache24\modules目录中
  • Apache24/conf目录下新建mod_jk.confworkers.properties文件
mod_jk.conf
LoadModule jk_module modules/mod_jk.so

JkWorkersFile conf/workers.properties

JkShmFile logs/mod_jk.shm

JkLogFile logs/mod_jk.log

JkLogLevel info

JkMount /* controller

JkMount /jkstatus status   
Workers.properties
worker.list=controller,status

worker.maintain=60

#========tomcat1========

worker.tomcat1.type=ajp13     

worker.tomcat1.host=192.168.10.39

worker.tomcat1.port=8017     

worker.tomcat1.lbfactor=1      

#========tomcat2========

worker.tomcat2.type=ajp13

worker.tomcat2.host=192.168.10.44

worker.tomcat2.port=8009

worker.tomcat2.lbfactor=1

#========controller,负载均衡控制器========

worker.controller.type=lb          

worker.controller.balance_workers=tomcat1,tomcat2

worker.controller.sticky_session=true     

#worker.controller.sticky_session_force=1

worker.status.type=status
  • 在httpd.conf的最后添加一行,引入mod_jk.conf配置文件
include conf/mod_jk.conf
分别启动Tomcat,然后启动httpd服务。浏览器地址访问 192.168.10.152:1314/share

附录

Dos命令启动Apache服务: Httpd.exe -w -n “Apache” -k start
参考 :http://www.cnblogs.com/icenter/p/5328383.html

问题

  1. dos命令安装httpd服务;httpd.exe -k install -n Apache提示丢失dll文件
    image

解决办法: 下载vc++2015并安装 https://www.microsoft.com/zh-cn/download/confirmation.aspx?id=48145

  1. 安装成功启动服务报错
    image

解决办法: 使用doc命令启动httpd.exe
image
通过输出信息,检查配置文件定位问题

标签:httpd,tomcat,worker,conf,jk,Apache,mod
来源: https://www.cnblogs.com/meideprac/p/16666795.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有