如何在不停止和重新启动的情况下部署 Web 应用程序

huangapple go评论69阅读模式
英文:

How to deploy a web app without stop and restart

问题

我之前将项目构建为二进制文件并部署到服务器上,然后使用nohup启动它。但是如果我更新了代码并重新构建程序,我必须先终止进程,然后更新文件并重新启动。

我的问题是:

  1. 应用程序必须至少停机几秒钟。
  2. 我必须手动更新文件(登录服务器,终止进程,替换文件,然后重新启动)。

是否有一种类似于PHP的热更新程序的方法?我只需要通过git(或svn或其他方式)将我的代码更新到服务器上,然后服务器将重新构建应用程序并优雅地重新启动。

英文:

I built the project to binary file and deployed it to server before. and start it with nohup. But if I updated my code and rebuild my program. I must to kill the process first, then updated the file and start again.

My problem is:

  1. The app must be down with at least few seconds.
  2. I must update file manually (login the server, kill process, replace file, and then start it)

Is there anyway to hot update the program, something like PHP? I just need update my code to server by git (or svn or others way). then the server will rebuild app and graceful restart it.

答案1

得分: 5

通常情况下,您会在反向代理(例如nginx或其他负载均衡器)后运行多个Web应用程序实例。如果几秒钟的停机时间对您来说是一个问题,那么您需要设置高可用性(HA)。在这种设置中,您可以进行滚动更新,逐个替换实例。

通过快速搜索,您可以找到有关如何进行部署的说明,例如:https://www.digitalocean.com/community/tutorials/how-to-deploy-a-go-web-application-using-nginx-on-ubuntu-18-04

英文:

Usually you run more than one instance of your web application behind a reversed proxy, eg nginx, or any other load balancer. If the few second downtime is an issue for you then you need to have a HA setup anyway. And in such setup you can do a rolling update, where you are replacing instances one by one.
Quick googling will let you find instructions how to do the deployment eg: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-go-web-application-using-nginx-on-ubuntu-18-04

huangapple
  • 本文由 发表于 2021年7月9日 19:13:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/68315835.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定