简体   繁体   English

如何更新网站而不使其崩溃?

[英]How to update a website without making it go down?

I need the best practice for updating one or more files on my website without making it go down;我需要最佳实践来更新我网站上的一个或多个文件而不会使其停机;

example, if i update Model.php file, the upload will take few seconds, like one or two seconds before it replaces the file on the server, in the meantime, the website will show some error that model.php is not found, or not complete, even if i suppress the errors, the website will die eventually.例如,如果我更新 Model.php 文件,上传将需要几秒钟,比如一两秒钟,然后它会替换服务器上的文件,同时,网站会显示一些错误,即找不到 model.php,或者不完整,即使我抑制了错误,该网站最终也会死亡。

what is the best practice for that?最好的做法是什么?

One practice I've often used and seen in practice is -我经常使用并在实践中看到的一种做法是-

  • use a Version Control System (VCS) like SVN or Git使用版本控制系统 (VCS),如 SVN 或 Git

  • on the live server, make the site's web root a symbolic link to a directory containing the latest revision of your web site (eg. /www/domain.com/r555 ) for revision no.在实时服务器上,使站点的 Web 根目录成为指向包含网站最新版本(例如/www/domain.com/r555 )的目录的符号链接,以获取版本号。 555 555

  • when a change comes up, check in changes to the VCS当发生更改时,检查对 VCS 的更改

  • have a script that checks out the latest revision to a new directory, carrying the revision name (say, /www/domain.com/r556 )有一个脚本可以将最新修订版检出到新目录,并带有修订版名称(例如/www/domain.com/r556

  • when the checkout is done, change the symbolic link and make it point to /www/domain.com/r556 .结帐完成后,更改符号链接并使其指向/www/domain.com/r556

There are a few snags if you have dynamic data like file uploads and such that you can't have in the VCS, but they can all be dealt with without downtime.如果您有动态数据(如文件上传)以及 VCS 中无法提供的动态数据,则有一些障碍,但它们都可以在不停机的情况下处理。

Things like database changes may still require some kind of maintenance mode, though.不过,诸如数据库更改之类的事情可能仍然需要某种维护模式。

When your updating production, create a folder called 1.1 and put the new application in there (whether manually or through some VCS) then symlink the public html directory to it.当您更新产品时,创建一个名为1.1的文件夹并将新应用程序放入其中(无论是手动还是通过某些 VCS),然后将公共 html 目录符号链接到它。 The switch will be instantaneous.开关将是瞬时的。

This is not an uncommon approach as one of the benefits is if there's something wrong with the code, the admin can immediately symlink back to the 1.0 folder.这种方法并不少见,因为好处之一是如果代码有问题,管理员可以立即符号链接回1.0文件夹。

Another good thing is to name the VCS tag the same as folder so the version in use can be easily tracked.另一个好处是将 VCS 标签命名为与文件夹相同的名称,以便可以轻松跟踪正在使用的版本。

Use a caching server/application to keep a cached copy available for users.使用缓存服务器/应用程序为用户保留缓存副本。 Varnish is an example.清漆就是一个例子。 You can set Varnish to cache contents for a set amount of time, and an alternative amount of time in case the actual website's server is not accessible ( Model.php not found errors and similar).您可以将 Varnish 设置为在一定时间内缓存内容,以及在无法访问实际网站服务器( Model.php not found错误等)的情况下的备用时间。

In this case if you update your production system, Varnish can keep on serving a cached copy of the website until the backend is up and running properly again (be it 2 seconds or 2 hours).在这种情况下,如果您更新生产系统,Varnish 可以继续提供网站的缓存副本,直到后端启动并再次正常运行(2 秒或 2 小时)。 Just remember to purge the Varnish cache after updates in case something (UI, content, etc.) changes for the users.请记住在更新后清除 Varnish 缓存,以防用户的某些内容(UI、内容等)发生变化。

All web servers have some caching features available, but Varnish and the like are made for caching.所有的 Web 服务器都有一些可用的缓存功能,但 Varnish 等是缓存而设计的。

Another option is to run two or more instances of the same website behind a load balancer like HAProxy .另一种选择是在负载均衡器(如HAProxy )后面运行同一网站的两个或多个实例。 Update one at a time and HAProxy can redirect traffic to the one that you are not currently updating.一次更新一个,HAProxy 可以将流量重定向到您当前未更新的那个。

Head over to Server Fault in case you need more information on server level caching or load balancing.如果您需要有关服务器级缓存或负载平衡的更多信息,请转至Server Fault

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM