英文:
How to deploy a web app without stop and restart
问题
我之前将项目构建为二进制文件并部署到服务器上,然后使用nohup
启动它。但是如果我更新了代码并重新构建程序,我必须先终止进程,然后更新文件并重新启动。
我的问题是:
- 应用程序必须至少停机几秒钟。
- 我必须手动更新文件(登录服务器,终止进程,替换文件,然后重新启动)。
是否有一种类似于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:
- The app must be down with at least few seconds.
- 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论