简体   繁体   English

为Web应用程序设置负载平衡环境的最佳/正确方法是什么?

[英]What the best/correct way to setup a load balanced environment for a web application?

I develop a web application that needs to be load balanced across 4 webservers. 我开发了一个Web应用程序,该应用程序需要在4个Web服务器之间进行负载平衡。 My company is purchasing the load balancer hardware (Cisco). 我的公司正在购买负载平衡器硬件(Cisco)。 There is confusion on how to tell the load balancer that a webserver should be in the rotation. 关于如何告诉负载均衡器网络服务器应该处于旋转状态,存在一些困惑。

The IT Hardware support team wants me to create a one page web application that will sit next to the main web application. IT硬件支持团队希望我创建一个单页Web应用程序,该应用程序将与主Web应用程序相邻。 I was told that this small one page app should call the database and do an INSERT, UPDATE, and DELETE on a table. 有人告诉我,这个很小的一页应用程序应该调用数据库并在表上执行INSERT,UPDATE和DELETE。 Then the app should return a status code, which in turn the load balancer will be able to read and determine whether to keep this webserver in the rotation. 然后,应用程序应返回状态码,负载平衡器将能够读取该状态码,并确定是否将此Web服务器保持在旋转状态。 This app will have to reside on all of the load balanced servers. 此应用程序必须驻留在所有负载平衡的服务器上。 The one page app would then be polled every 5 seconds by the load balancer. 然后,负载平衡器将每5秒轮询一次一页应用程序。

I think that this sounds like an absolute HACK. 我认为这听起来像是绝对的HACK。 It sounds like unnecessary work and overhead on the database. 听起来好像不必要的工作和数据库开销。 The hardware team is trying to convince me that this is the right way to go. 硬件团队正在试图说服我这是正确的方法。 I completely DISAGREE! 我完全不同意! My argument is that the load balancer should not care about the database connection. 我的观点是负载均衡器不应该关心数据库连接。 We are only trying to distribute the load across the 4 webservers. 我们仅尝试在4个Web服务器之间分配负载。 One thing to note is that the Main Web Application is useless without its database connection. 需要注意的一件事是,如果没有数据库连接,主Web应用程序将毫无用处。

Does the load balancer itself have a way to determine if a server should be in the rotation? 负载均衡器本身是否可以确定服务器是否应该轮换使用? What is the correct way to do this? 正确的方法是什么?

Read Scalable Internet Architectures . 阅读可伸缩的Internet体系结构

The balancer can only see the web servers. 平衡器只能看到Web服务器。 If the web server appears up, but can't talk to the database (because, say, Apache is running but your app is broken), then you'll have a problem with the non-responsive server getting requests when the app is broken. 如果Web服务器出现了,但无法与数据库通信(例如,Apache正在运行,但是您的应用程序已损坏),那么当应用程序损坏时,无响应服务器将无法获取请求。

We have a selftest app that returns some status. 我们有一个返回一些状态的自测应用程序。 Currently used for debugging. 当前用于调试。 In the future, will be used with other HA and load-sharing solutions. 将来,它将与其他HA和负载共享解决方案一起使用。

I always put a real simple html page on the webserver. 我总是在网络服务器上放置一个真正简单的html页面。 If the HTTP status from status.html comes back 200, then keep the server in the rotation, if not, suspend the web server. 如果status.html的HTTP状态返回200,则保持服务器旋转,如果没有,请暂停Web服务器。

What if your DB goes down hard? 如果您的数据库严重崩溃怎么办? while you are restoring, you should be able to place a status message that says "sorry, back soon". 在还原时,您应该能够显示一条状态消息,“抱歉,很快回来”。 You don't want to have to reconfigure your load balancer as well. 您也不需要重新配置负载均衡器。 Is there no part of your application that can run without the DB? 没有DB,您的应用程序中没有部分可以运行吗?

It is not a hack, but a common way to check the heartbeat of web servers . 这不是黑客,而是检查Web服务器心跳的一种常用方法。 However, querying database in that page is controversial. 但是,在该页面中查询数据库存在争议。 For example, you may end up with no web servers in cluster in case of DB timeout. 例如,如果数据库超时,您可能最终在群集中没有Web服务器。

I believe it is a hack. 我相信这是黑客。 The load balancer should just use a simple html page to return to the load balancer like JWMiller said. 负载平衡器应该只使用一个简单的html页面返回到负载平衡器,就像JWMiller所说的那样。 we use this approach accross all our apps. 我们在所有应用程序中都使用这种方法。 Checking database connections, remoted services, etc. is the job of an application healthcheck and should be a separate function. 检查数据库连接,远程服务等是应用程序运行状况检查的工作,并且应该是单独的功能。

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

相关问题 设计.NET Web应用程序的正确方法是什么? - What is the correct way to design a .NET web application? 设置个人.NET Web开发环境的最简单方法是什么? - What's the easiest way to setup a personal .NET web development environment? 跨AWS上负载平衡的Windows实例同步文件的最佳方法? - Best way to sync files across load balanced Windows instances on AWS? 什么是Microsoft开发环境安装最佳实践 - What are Microsoft Development Environment Setup Best Practices 从Web应用程序创建锁的最佳方法是什么? - What is the best way to create a lock from a web application? 自动部署到 F5 负载平衡环境 - Automated Deployment to an F5 Load Balanced Environment 在负载平衡环境中进行部署的WIF 4.0问题 - WIF 4.0 issue with deployment on load balanced environment 在Web应用程序中使用静态方法的正确方法 - Correct way to use static methods in Web application 在 Roslyn 中加载便携式 MetadataReference 的正确方法是什么? - What is the correct way to load a portable MetadataReference in Roslyn? 在 F# Web API 应用程序中添加命名 HttpClient 的正确方法是什么? - What is the correct way to add a named HttpClient in an F# Web API application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM