问题描述
我们还没有持续集成设置.但是要非常频繁地部署.每天大约一次.
We have no continuous integration setup(, yet). But want to deploy very frequently. Once a day or so.
我们有一个非常标准的Django应用程序,带有一个单独的Postgres服务器.我们使用普通租用的VM(没有Amazon或Rackspace).
We have a pretty standard Django application with a separate Postgres server. We use normal rented VMs (NO Amazon or Rackspace).
我们如何最大程度地减少应用程序的停机时间?最好的办法是将停机时间降至零.我们考虑了使用两个相等的应用程序和两个数据库服务器的设置,然后再部署一对应用程序/数据库服务器.
How can we minimize the downtime of our application? Best would be to zero downtime. We thought about a setup with two equal application and two database servers and deploy one app/db server pair after another.
问题在于保持数据一致.当一个应用程序/数据库服务器对正在更新时,使用旧代码的服务器对可以为用户服务.但是,如果用户写入数据库,则在切换到更新后的数据对时,我们将丢失数据.尤其是当我们进行模式迁移时.
The problem is keeping the data consistant. While one app/db server pair is updating the server pair with the old code can serve users. But if the users write to the db we would lose the data when switching to the updated pair. Especially when we push schema migrations.
我们该如何处理?这肯定是一个非常普遍的问题,但我找不到很好的答案.您如何处理这个问题?
How can we handle this? This must be a very common problem but I can't find good answers. How do you handle this problem?
推荐答案
在没有架构迁移的情况下,我将为您提供一个实际方案:
In the case that you have no schema migrations, I'll give you a practical scenario:
保留两个版本的django进程(A和B),您可以使用它们来控制,比如说主管.将nginx进程放在django进程的前面,该进程会将所有请求转发到A.因此,您将版本B上传到服务器,使用超级用户启动django进程B,然后将nginx的conf文件更改为指向B,然后重新加载nginx进程..
Keep two versions of django processes ( A and B ), which you control with, let's say, supervisor. Keep an nginx process in front of your django processes, which forwards all requests to A. So, you upload version B to the server, start the django process B with supervisor, then change your nginx's conf file to point to B, then reload your nginx process..
在进行模式迁移的情况下,事情会变得很复杂.您的选择包括:
In the case that you have schema migrations, things get complicated. Your options include:
- 您可以考虑使用像mongoDB这样的NoSQL解决方案(在这种情况下,您可以保留一个数据库实例).
- 弄清楚如何在上传时手动记录所有写请求,以便稍后将它们推送到新数据库中.
这篇关于部署Django应用程序而不会中断服务/不会造成停机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!