AWS 云上的 LAMP 托管 - 需要重写哪些 PHP 代码?
我想在云上托管 PHP 应用程序以利用按需可扩展性。我担心如果我的应用程序出现在 Digg/Slashdot/流行博客(希望所有这些地方)上,那么我的网站很可能会崩溃。因此,我正在研究 A*mazon EC2、RackSpace 云服务器等。*但我对云架构感到困惑。在基于常规 cPanel 的共享主机上托管 PHP 应用程序非常简单。通过 FTP 将代码上传到 public_html 目录,然后就完成了。
但有了云,我们就有了多个服务器。我的理解是,在云中,您会在某些负载均衡器后面获得一些虚拟机空间。当您需要更多资源时,只需配置另一个虚拟机即可。负载均衡器向所有可用资源发送请求。 那么,您如何处理这些事情:
- 会话管理/会话连续性: 现在,显而易见的事情之一是 Cloud-Server-1 不会知道 Cloud-Server-2 上的用户会话。那么,在基于云的托管中如何管理呢?我是否需要重新编写一些处理会话的 PHP 代码? (我正在考虑托管在Yii框架中完成的电子商务PHP脚本)
处理会话的PHP代码是否需要重写或 是否有一个抽象层来处理它?基本上,我只是简单地 通过 FTP 上传应用程序,然后由一些抽象层负责 还是我必须重新编写一些代码?
数据库扩展:当负载很重时,我想我可以配置 Amazon EC2 或任何云服务器来自动配置更多服务器。此外,无论如何,拥有多个服务器以提高速度和可靠性可能是个好主意。但我不确定这是如何运作的。我的意思是,数据库中的“数据”必须共享。
那么,如何维护多个数据库服务器?如果每个数据库都是彼此的实时副本。那么如何减少负载呢?我的意思是,如果您在 DB1 上执行查询,然后实时地在 DB2 中执行此查询(如果不是,DB2 中的数据将与 DB1 不同),那么两个 DB 将具有相同的负载。
我正在考虑的一些云服务器是:
- Amazon EC2
- RackSpace 云站点
- RackSpace 云服务器
- PagodaBox(仍处于测试阶段,但不允许 cron): http://www.pagodabox.com/
- Go Grid 可扩展网站架构:http://www.gogrid.com/cloud-hosting/cloud -hosting-packages/scalable-website.php(虽然这是非常非常昂贵的。我希望从一台服务器开始,然后自动提供额外的网络服务器和/或额外的数据库-处理负载峰值的服务器根据需要)
任何提示将不胜感激。
谢谢
I want to host a PHP application on Cloud to take advantage of on-demand scalability. I am afraid if my application were to get featured on Digg/Slashdot/popular blogs (hopefully all of these places) then my site would very likely crash. So, I was looking into A*mazon EC2, RackSpace Cloud Servers etc.* But I am confused by Cloud Architecture. Hosting a PHP application on regular cPanel based shared-hosting is very simple. FTP upload your code to public_html directory and you are done.
But with cloud, we'd have multiple servers. My understanding is that in Cloud, you get some VM space behind some load-balancer. When you need more resources, you simply provision another VM. Load balancer sends request to all available resources.
So, how do you deal with these things:
- Session management/session continuity:
Now, one of the obvious thing here is that Cloud-Server-1 is not going to be aware of user-session on Cloud-Server-2. So, how is this managed in cloud based hosting? Would I be required to re-write some PHP code that deals with sessions?
(I am thinking of hosting an e-commerce PHP script done in Yii framework) Would the PHP code that deals with session need to be re-written or
is there an abstraction layer that handles it? Basically, do I simply
FTP upload the application and then some abstraction layer takes care
of everything or do I have to re-write some code?Database scaling: When there is heavy load, I think I can configure Amazon EC2 or any cloud-server to automatically provision more servers. And besides, it's probably a good idea to have multiple servers anyway to increase speed and reliability. But I am not sure how that works. I mean, the "data" in the database has to be shared.
So, how are multiple database-servers maintained? If each database is a real-time copy of each other. Then how will it reduce load? I mean, if you do a query on DB1, and then in real-time, this query is also done in DB2 (if not, the data in DB2 would not be same as DB1) then both DB will have same load.
Some Cloud Servers I am considering are:
- Amazon EC2
- RackSpace Cloud Sites
- RackSpace Cloud Servers
- PagodaBox (still in BETA and does not allow crons though): http://www.pagodabox.com/
- Go Grid scalable website architecture: http://www.gogrid.com/cloud-hosting/cloud-hosting-packages/scalable-website.php (although this is very very expensive. I was hoping to start with a single server to begin with and then automatically provision extra web-servers and/or extra DB-servers to handle load spikes as needed)
Any tips would be appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我与一家托管公司的技术支持人员进行了交谈。他看起来不像一个超级极客,但他给了我这个建议:创建多个网络服务器和服务器。多个数据库服务器。方法如下:
多个服务器上的应用程序。最初启动 1 台服务器。如果
负载高,启动其他映像。负载均衡器会
自动开始向您的网络的这个新实例发送查询
服务器。
奴隶。
他说,您需要重写一些 PHP 代码并执行以下操作:
会话处理:他说修改您的 PHP 代码,以便将会话存储在“数据库”。
数据库相关代码:删除所有“连接”操作。我不确定这是否可以删除所有连接操作。 有关如何执行此操作的任何提示?是否无法在保留“加入”操作的同时进行“扩展”?
就这样。真的吗,是这个吗?或者您认为还有其他事情需要注意吗?
另外,创建多个数据库服务器实例(主从)。只写给master。我需要至少有两 (2) 个数据库服务器始终运行。 如果负载不高,我不是要无缘无故地支付额外的数据库服务器费用吗?
I talked to tech-support of a hosting company. He didn't seem like a uber-geek but he gave me this advise: create multiple web-servers & multiple DB servers. Here is how:
application on multiple servers. Start-up 1 server initially. If the
load is high, start-up the other image. Load balancer would
automatically start sending queries to this new instance of your web
server.
slaves.
He said, you'd need to rewrite some PHP code and do the following:
Session handling: he said modify your PHP code so that sessions are stored in "DB" .
DB related code: Remove all "join" operations. I am not sure if this is even possible to remove ALL join operations. Any tips on how to do this? Is there no way to "scale" while retaining "join" operations?
That's all. Really, is it this it? Or do you think there are other things to take care of as well?
Also, to create multiple DB server instances (master-slave). Write to master only. I would need have at-least two (2) DB servers running at ALL times. If the load isn't high, wouldnt I be paying for extra DB server for no reason?