本文介绍了Tomcat负载均衡器解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个与Tomcat一起使用的良好负载均衡器。我们的应用程序不会在会话上下文中存储任何内容,因此为同一用户重定向到同一服务器并不重要。我只是喜欢能够循环排队请求或基于每个服务器的个人负载排队的东西。我还希望能够将应用程序服务器添加到可用于处理请求的服务器,而无需重新启动负载均衡器。如果重要的话,我们在linux上运行应用程序。

I'm looking for a good load balancer to use with 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上的软件负载均衡器,请使用Apache Webserver2,Mod-Jk和Tomcat集群:

If all you need is a software load balancer on linux use Apache Webserver2, Mod-Jk and Tomcat Clustering:

在您的网络服务器上:

1)安装apache2和modjk:

1) Install apache2 and modjk:

sudo apt-get install apache2 libapache2-mod-jk
sudo a2enmod jk

2)创建apache2可用的workers.properties文件。在某些情况下,会自动在/ etc / apache2目录中创建。此文件包含Tomcat服务器的lb配置,节点名称,ips和端口,即:

2) Create a "workers.properties" file available to your apache2. In some cases ist automatically created in your /etc/apache2 directory. This file is holding the lb config, node names, ips and ports of your Tomcat servers, i.e.:

worker.list=balancer,lbstats

#node1
worker.node1.type=ajp13
worker.node1.host=NODE-IP
worker.node1.port=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:
worker.balancer.balance_workers=node1

#lb status information (optional)
worker.lbstats.type=status

3)如果尚未自动创建,请在apache2配置文件中创建一个Mod-Jk部分。

3) Create a Mod-Jk section in your apache2 config file, if it has not been created automatically.

JkWorkersFile   /etc/apache2/workers.properties
JkLogFile       /var/log/apache2/mod_jk.log
JkShmFile       /tmp/jk-runtime-status
JkLogLevel      info

4)将您的应用程序挂载到负载均衡器(apache2配置文件):

4) Mount your application to the load balancer (apache2 config file):

JkMount /MyApp       balancer
JkMount /MyApp/*     balancer

JkMount /modjkstatus lbstats

在Tomcat服务器上:

At your Tomcat servers:

5)使用tarball包安装tomcat(比apt verison更好)。更改server.xml:

5) Install tomcat using the tarball package (way better then the apt verison). Change server.xml:


  1. 禁用http连接器。

  2. 启用AJP / 1.3连接器并设置您在此节点的workers.properties中定义的端口。

  3. 将具有正确节点名称的jvmRoute添加到Engine元素:

  1. disable the http connectors.
  2. enable AJP/1.3 connector and set the port you defined in workers.properties for this node.
  3. add jvmRoute with the right node name to the "Engine" element:

<Engine jvmRoute="node1" ...


  • 为最简单的配置添加Cluster元素

  • add a "Cluster" element for simplest configuration

    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" />
    


  • 6)将应用程序部署到所有的tomcats和将可分发元素添加到web.xml。

    6) Deploy your application to all tomcats and add a distributable element to your web.xml.

    <distributable/>
    

    7)确保网络服务器可以访问tomcat服务器上的ajp端口,而其他任何人都无法访问。

    7) Make sure the webserver can access the ajp ports on your tomcat servers and no one else can.

    8)一个接一个地启动网络服务器和tomcats并检查日志(/var/log/apache2/mod_jk.log)。

    8) Start the webserver and the tomcats one after another and check the logs (/var/log/apache2/mod_jk.log, too).

    9)访问您的应用:

    9) Access your app: http://mywebserver.com/MyApp

    10)检查(并拒绝访问)lb状态页面

    10) Check (and deny access to) the lb status page http://mywebserver.com/modjkstatus

    这篇关于Tomcat负载均衡器解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    09-01 22:22