使用buildout部署到生产环境并实现最小停机时间?

4 投票
1 回答
1108 浏览
提问于 2025-04-16 18:15

我有一个使用 Django 和 WSGI 的项目,在开发和生产环境中运行得很好。唯一的问题是,每当我对 buildout.cfg 文件进行修改或添加内容,并且需要运行 bin/buildout 时,网站就会从开始运行 buildout 到完成期间下线。这段时间可能会超过 5 分钟。

有没有什么办法可以让 buildout 在生产环境中优雅地运行呢?也许有我不知道的参数,可以在不先卸载所有东西的情况下运行 buildout?这个网站目前只在一台服务器上运行。虽然增加负载均衡器和额外的服务器是个不错的解决办法,但在这个时候并不现实。

对于我的 buildout 脚本,欢迎任何其他的评论、建议或批评。

谢谢!

这是我的 buildout.cfg 文件:

[buildout]
download-cache = downloads
unzip = true
parts =
    scripts
    django
    djangoprod

eggs = 
    ${scripts:eggs} 
    ${pipscripts:eggs}

[scripts]
recipe = zc.recipe.egg
unzip = true
download-cache = ${buildout:download-cache}
eggs =
    ipython
    docutils
    feedparser
    pygments
    South
    django-grappelli
    django-extensions
    django-mobile
    django-photologue
    django-filebrowser
    django-indexer
    django-paging
    django-templatetag-sugar
    django-sentry
    MySQL-python

find-links =
    http://dist.repoze.org/
    http://github.com/
    http://bitbucket.org/
    http://googlecode.com/
    http://surfnet.dl.sourceforge.net/

[pipscripts]
recipe = gp.recipe.pip
unzip = true
download-cache = ${buildout:download-cache}
editables = 
    hg+https://bitbucket.org/ubernostrum/django-registration#egg=django_registration
    git://github.com/jtauber/django-mailer.git#egg=django_mailer
eggs = 
    django-registration
    django-mailer
    PIL
install =
    http://effbot.org/downloads/Imaging-1.1.7.tar.gz

[django]
recipe = djangorecipe
download-cache = ${buildout:download-cache}
eggs = ${buildout:eggs}
version = 1.3
project = project

[djangoprod]
recipe = djangorecipe
download-cache = ${django:download-cache}
version = ${django:version}
settings = production
wsgi = true
eggs = ${django:eggs}
project = ${django:project}

1 个回答

4

Buildout 只会更新那些配置发生变化的部分(或者在某些情况下,可能是因为某些糟糕的配方实现)。一种方法是把 buildout 的配置复制或检出到一个新的位置,然后重新运行 buildout,接着停止旧的实例,最后在新的安装上重新启动实例。在某些情况下,我们会像这样维护安装:

/data/buildout_<date1>
/data/buildout_<date2>
/data/current

这里的 'current' 是一个指向当前 'buildout_' 安装的符号链接。

当然,还有一种方法是,在负载均衡器后面运行多个实例,在 buildout 阶段可以把某个实例从负载均衡器中移除。

撰写回答