两个 VPS 帐户上的 Django 冗余和复制

发布于 2024-08-13 04:26:22 字数 460 浏览 11 评论 0原文

我正在慢慢陷入这样的境地:我的 Django 网站需要一些强大的支持。我目前在带有 memcached 的 SQLite 数据库上的单个 VPS 上运行。它几乎是无法扩展的。

如果我购买另一个 VPS 帐户,我想做什么?

  • 通过复制迁移到 MySQL/PostgreSQL?什么是最简单的?复制是否可以保护我免受一台服务器爆炸的影响?并发有缺点吗?
  • 如何在两台服务器之间实现负载平衡?
  • 我也将 memcached 放在新服务器上。如果我将两个 IP 都放入配置中,是否会在两台服务器上保留数据副本? (我正在考虑会话数据会发生什么情况 - 当前存储在 memcached 中)
  • 我目前正在使用 Cherokee 作为 httpd - 我确信这有它自己的一系列问题。如果您有任何提示,请告诉我。

我这样做的方式是错误的吗?有没有更简单的方法来拥有更快、更强大的 django 站点?

I'm slowly getting into the position where one of my Django sites needs some robustness behind it. I'd currently running on a single VPS on a SQLite database with memcached.. It's about as un-scaled as things can get.

If I bought another VPS account, what would I want to do?

  • Move to MySQL/PostgreSQL with replication? What's easiest? Does replication protect me from one server exploding? Are there concurrency downsides?
  • How do I load-balance between the two servers?
  • I'd put memcached on the new server too. If I put both IPs into the configuration, would that keep a copy of data on both servers? (I'm thinking of what happens to session data - currently stored in memcached)
  • I'm currently using Cherokee as the httpd - I'm sure this has its own set of issues. If you've any tips, let me know.

Am I going at this the wrong way? Is there an easier way to have faster, more robust django sites?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

羁客 2024-08-20 04:26:22

第一步:从 SQLite 切换到真正的生产数据库(我喜欢 Postgres)。这应该早在您考虑第二个 VPS 之前就发生了。 SQLite本质上根本不支持并发。就我个人而言,我什至不会首先考虑在 SQLite 上部署实时站点。

如果您的网站在 SQLite 上运行并且正常运行,我的猜测是您距离实际超出单个 VPS 的容量还有很长的路要走(除非它已经负载很重)。

如果/当您确实需要添加第二台服务器时,您的配置方式取决于您实际看到瓶颈的位置。很可能是数据库,在这种情况下,一个好的步骤可能是简单地将数据库移动到自己的服务器上(假设您可以保证两个 VPS 之间的低延迟),并使用您可以承受的尽可能多的 RAM 加载数据库服务器。一般来说,VPS 中的磁盘性能受到的影响最大,因此要考虑的另一个步骤可能是将数据库放在原始金属上。

在考虑数据库复制或多个 Web 层服务器之前,我可能会先查看这些步骤,但这实际上取决于分析您的实际情况(以及您如何评估性能与可靠性)。

First step: switch from SQLite to a real production database (I like Postgres). This should happen long before you even think about a second VPS. SQLite essentially does not support concurrency at all. Personally, I wouldn't even consider deploying a live site on SQLite in the first place.

If your site is running on SQLite and is functioning, my guess is you are still quite a long ways from actually outgrowing your single VPS (unless it's already heavily loaded otherwise).

If/when you do need to add a second server, how you configure things depends on where you're actually seeing a bottleneck. Chances are it'll be the database, in which case a good step might be simply moving the database onto its own server (presuming you can guarantee low latency between the two VPSes) and loading the database server with as much RAM as you can afford. In general disk performance suffers most in a VPS, so another step to consider might be putting the DB onto raw metal.

I'd probably look at those steps before I'd think about DB replication or multiple web-tier servers, but it really depends on profiling your actual case (and how you value performance vs reliability).

烦人精 2024-08-20 04:26:22

观看 Jacob 的 Django 部署研讨会 Kaplan-Moss 应该会给你一个很好的概述。

MySQL 支持主从和主主设置我不使用 PostgreSQL。

您可以使用 nginx 作为负载均衡器,HAProxy 也是一个选项(所以使用它)。

Memcached 将对象分布在服务器上,如果服务器崩溃,数据就会丢失。

我不知道 Cherokee,但是 nginx 很棒。

Watching the Django Deployment Workshop by Jacob Kaplan-Moss should give you a good overview.

MySQL supports Master-Slave and Master-Master setups I don't use PostgreSQL.

You can use nginx as your loadbalancer, HAProxy is an option, too (SO use it).

Memcached distributes the objects over the servers, If one crashes the data is lost.

I don't know Cherokee, but nginx is great.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文