Deploy Django Application without Service Interruption / no Downtime

隐身守侯 提交于 2021-01-22 05:25:47

问题


We have no continuous integration setup(, yet). But want to deploy very frequently. Once a day or so.

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?


回答1:


In the case that you have no schema migrations, I'll give you a practical scenario:

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:

  • You could consider using a NoSQL solution, like mongoDB (in this case you can keep a single DB instance).
  • Figure out how to manually record all write requests while uploading, as to push them later to your new database.


来源:https://stackoverflow.com/questions/14440920/deploy-django-application-without-service-interruption-no-downtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!