如何负载平衡一个PHP应用程序? [英] How to load balance a php application?

查看:83
本文介绍了如何负载平衡一个PHP应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找有关如何平衡php应用程序的指南,建议或示例.我的设置是Ubuntu 10.04和PHP 5.3.我以前从未负载均衡服务器,现在正在寻找提供的任何帮助.

I am looking for guides, advice, or samples of how to load balance a php application. My setup is Ubuntu 10.04 and PHP 5.3. I have never load balanced servers before and I am looking for any help that is offered.

更新:
这是一个Web应用程序,预计将有数百个用户同时使用它. MySQL将成为数据库.将有用于用户的会话,但是我听说会话不能在多个服务器上进行.内容更新将非常频繁.会有文件,但是我只使用CDN.

Update:
It's a web application that is expected to have a few hundred users using it at the same time. MySQL will be the database. There will be sessions used for the users but I have heard that sessions cannot be carried over multiple servers. There will be very frequent content updates. There will be files but I'll just use a CDN for those.

推荐答案

Web应用程序的负载平衡与应用程序本身无关,而与托管和基础结构更多.但是,在构建应该实现负载平衡的应用程序时,仍然需要注意一些关键点.这里是一些:

load balancing a web application has not much to do with the application itself but more with hosting and infrastructure. However there are still some key points you have to pay attention when building an app that is supposed to be load balanced. Here are some:

  • 请勿使用状态服务器.意味着您无法使用传统的会话对象,因为它存储在本地计算机的内存中,因此一个对象可能在一台服务器中可用,而在另一台服务器中不可用
  • 请勿使用磁盘存储任何内容.与上述相同的原因.您可以将文件写入服务器1的磁盘中,然后尝试读取服务器2中的数据.
  • 最重要的是,您应该避免依赖于服务器的任何类型的资源.如果您需要使用类似这样的东西(状态服务器,磁盘等),则应该存储一个共享资源,以便所有负载平衡计算机都可以访问它

例如,如果这是现有应用程序遇到的问题,则可以通过在负载均衡器上设置相似性来解决此问题,这意味着来自特定用户的所有请求都将由同一服务器处理.显然,这种方法的缺点是使您的应用程序的可扩展性降低,因为一台服务器可以比另一台服务器获得更多的处理能力.

If this is a problem for an existing application, for example, you can workaround this by setting affinity on the Load Balancer meaning that all requests that come from a specific user will be served by the same server. Obviously this approach has the downside of making your app less scalable since one server can get more processing than the other.

因此,关于执行负载平衡器的软件,我不是Linux专家,但是我看到很多人都在谈论Apache作为WebServer,而HAProxy作为负载平衡器应用.

So, regarding the software to do the load balancer I'm not a Linux guy but I see lots of people talking about Apache as WebServer and HAProxy as the load balancer app.

希望有帮助!

这篇关于如何负载平衡一个PHP应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆