简体   繁体   English

Tomcat负载均衡解决方案

[英]Tomcat load balancer solutions

I'm looking for a good load balancer to use with Tomcat.我正在寻找与 Tomcat 一起使用的良好负载平衡器。 Our application doesn't store anything in the session context so it isn't important to redirect to same server for the same user.我们的应用程序不会在会话上下文中存储任何内容,因此为同一用户重定向到同一服务器并不重要。 I'd simply like something that can queue requests round-robin style or based on each server's inidividual load.我只是想要一些可以以循环方式或基于每个服务器的独立负载对请求进行排队的东西。 I'd also like to be able to add application servers to those available to handle requests without having to restart the load balancer.我还希望能够将应用程序服务器添加到可用于处理请求的应用程序服务器中,而无需重新启动负载平衡器。 We're running the application on linux if that matters.如果这很重要,我们将在 linux 上运行该应用程序。

If all you need is a software load balancer on linux use Apache Webserver2, Mod-Jk and Tomcat Clustering:如果您只需要一个 linux 上的软件负载平衡器,请使用 Apache Webserver2、Mod-Jk 和 Tomcat 集群:

At your Webserver:在您的网络服务器上:

  1. Install apache2 and modjk:安装 apache2 和 modjk:

     sudo apt-get install apache2 libapache2-mod-jk sudo a2enmod jk
  2. Create a workers.properties file available to your apache2.创建一个可用于 apache2 的workers.properties文件。 In some cases it's automatically created in your /etc/apache2 directory.在某些情况下,它会自动在您的 /etc/apache2 目录中创建。 This file is holding the lb config, node names, ips and ports of your Tomcat servers, ie:该文件包含 Tomcat 服务器的 lb 配置、节点名称、ips 和端口,即:

     worker.list=balancer,lbstats #node1 worker.node1.type=ajp13 worker.node1.host=YOUR_TOMCAT-NODE-IP worker.node1.port=YOUR_TOMCAT-NODE-AJP-PORT worker.node1.lbfactor=10 #more nodes here ... (change name in between) #lb config worker.balancer.type=lb #turn off sticky session worker.balancer.sticky_session=0 #add all defined node names to this list (node1, node2, ...): worker.balancer.balance_workers=node1 #lb status information (optional) worker.lbstats.type=status
  3. Create a Mod-Jk section in your apache2 config file, if it has not been created automatically.如果没有自动创建,请在 apache2 配置文件中创建一个 Mod-Jk 部分。

     JkWorkersFile /etc/apache2/workers.properties JkLogFile /var/log/apache2/mod_jk.log JkShmFile /tmp/jk-runtime-status JkLogLevel info
  4. Mount your application to the load balancer (apache2 config file):将您的应用程序挂载到负载均衡器(apache2 配置文件):

     JkMount /My-Java-App-Name balancer JkMount /My-Java-App-Name/* balancer JkMount /modjkstatus lbstats

At your Tomcat servers:在您的 Tomcat 服务器上:

  1. Install tomcat (using the tarball package, imho, way better then the apt verison).安装 tomcat(使用 tarball 包,恕我直言,比 apt verison 好得多)。 Change server.xml:更改 server.xml:

    1. disable the http connectors in server.xml (by commenting them out).禁用server.xml的 http 连接器(通过注释掉它们)。

    2. enable AJP/1.3 connector and set the port you defined in workers.properties for this node.启用 AJP/1.3 连接器并为此节点设置您在 workers.properties 中定义的端口。

    3. add jvmRoute with the right node name to the "Engine" element:将具有正确节点名称的 jvmRoute 添加到“Engine”元素:

      <Engine jvmRoute="node1" ... <Engine jvmRoute="node1" ...

    4. add a "Cluster" element for simplest configuration为最简单的配置添加一个“集群”元素

       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" />
  2. Deploy your application to all tomcats and add a distributable element to your applications web.xml.将您的应用程序部署到所有 tomcat,并将可distributable元素添加到您的应用程序 web.xml。

     <distributable/>
  3. Make sure the webserver can access the ajp ports on your tomcat servers and no one else can.确保网络服务器可以访问您的 tomcat 服务器上的 ajp 端口,而其他任何人都不能。

  4. Start the webserver and the tomcats one after another and check the logs (/var/log/apache2/mod_jk.log, too).一个接一个地启动 webserver 和 tomcats 并检查日志(/var/log/apache2/mod_jk.log,也是)。

  5. Access your app: http://mywebserver.com/MyApp访问您的应用程序: http : //mywebserver.com/MyApp

  6. Check (and deny access to) the lb status page http://mywebserver.com/modjkstatus检查(并拒绝访问)lb 状态页面http://mywebserver.com/modjkstatus

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有负载平衡器的Tomcat集群 - Tomcat clustering without load balancer 从Tomcat控制负载均衡器的路由 - Control the routing of load balancer from a Tomcat Tomcat Web应用程序能否告知负载均衡器其Tomcat已关闭? - Can a Tomcat web application tell a load balancer its Tomcat is down? 当2个tomcat位于不同机器中时,如何在tomcat中实现负载均衡? - How to implement load balancer in tomcat when 2 tomcats are in different machines? 如何使用Apache负载平衡器配置Tomcat实例故障转移设置? - How to configure Tomcat instance fail over setup with Apache load balancer? 使用Apache mod_jk,tomcat的后备负载均衡器 - Fallback Load balancer with apache mod_jk, tomcat 只能将tomcat用作负载平衡器(没有Apache Http Server) - Can only tomcat be used as a load balancer(without Apache Http Server) Tomcat在部署War文件之前对负载均衡器端口检查成功做出响应 - Tomcat responding success to load balancer port check before war files deployed 如何从位于负载均衡器后面的tomcat服务器中检索端口号 - How to retrieve port number from a tomcat server sitting behind a load-balancer Tomcat是否可以告诉mod_jk的负载平衡器在过载时使用另一个工作程序? 如果是这样,怎么办? - Can Tomcat tell mod_jk's load balancer to use another worker when overloaded? If so, how?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM