[英]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:在您的网络服务器上:
Install apache2 and modjk:安装 apache2 和 modjk:
sudo apt-get install apache2 libapache2-mod-jk sudo a2enmod jk
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
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
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 服务器上:
Install tomcat (using the tarball package, imho, way better then the apt verison).安装 tomcat(使用 tarball 包,恕我直言,比 apt verison 好得多)。 Change server.xml:
更改 server.xml:
disable the http connectors in server.xml
(by commenting them out).禁用
server.xml
的 http 连接器(通过注释掉它们)。
enable AJP/1.3 connector and set the port you defined in workers.properties for this node.启用 AJP/1.3 连接器并为此节点设置您在 workers.properties 中定义的端口。
add jvmRoute with the right node name to the "Engine" element:将具有正确节点名称的 jvmRoute 添加到“Engine”元素:
<Engine jvmRoute="node1" ... <Engine jvmRoute="node1" ...
add a "Cluster" element for simplest configuration为最简单的配置添加一个“集群”元素
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" />
Deploy your application to all tomcats and add a distributable
element to your applications web.xml.将您的应用程序部署到所有 tomcat,并将可
distributable
元素添加到您的应用程序 web.xml。
<distributable/>
Make sure the webserver can access the ajp ports on your tomcat servers and no one else can.确保网络服务器可以访问您的 tomcat 服务器上的 ajp 端口,而其他任何人都不能。
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,也是)。
Access your app: http://mywebserver.com/MyApp访问您的应用程序: http : //mywebserver.com/MyApp
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.