无需重新启动即可无缝部署Go服务器的补丁。

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

Seamless Patch Deploy of Go Server Without Restarting

问题

我很好奇是否有一种方法可以在不关闭和重新启动服务器的情况下部署Go服务器。我知道像ASP.Net和PHP这样的流行解决方案可以无缝处理用户会话。

无状态会话是否可以解决这个问题?

英文:

I was curious if there are any solutions to deploying a go server without the need shut it down and relaunch it. I know popular solutions like ASP.Net and PHP and the like will do this seamlessly for user sessions.

Will stateless sessions take care of this issue?

答案1

得分: 1

这种无缝部署方式可以通过引入请求路由器(如nginxHAProxy)来实现,即使是最简单的应用服务器也可以。这两个路由器都允许你将请求转发到不同的服务(称为反向代理),并在重新加载配置时不中断连接。举个例子:

  • 配置你的路由器监听0.0.0.0:80并将这些请求转发到127.0.0.1:5001
  • 127.0.0.1:5001上运行你的应用服务器v1。
  • 在这个设置中,当用户向你的路由器发出请求时,它们将被转发到应用程序v1服务器。
  • 在部署新版本v2的应用程序时,将其配置为监听端口127.0.0.1:5002
  • 更改路由器配置,使其将流量转发到127.0.0.1:5002。然后告诉路由器重新加载配置。
  • 现在,当用户向你的路由器发出新请求时,它们将被转发到应用程序v2服务器。
  • 一旦v1停止接收流量,你可以安全地关闭它。如果v2出现问题,你可以通过恢复路由器配置来回滚到v1,因此在后台保持v1运行是有好处的。

这只是一个简化的高级概述。(例如,你应该优先使用Unix套接字而不是回环接口。)这种部署方式通常被称为金丝雀或蓝绿部署

英文:

This kind of seemless deployment can be achieved for even the most naive of application servers by introducing a request router such as nginx or haproxy. Both of these routers allow you to forward requests to different services (known as a reverse-proxy), and reload their configuration without dropping connections. By way of an example:

  • Configure your router to listen on 0.0.0.0.80 and forward these requests to 127.0.0.1:5001.
  • Run your application server v1 on 127.0.0.1:5001.
  • In this setup when your users make requests to your router, they will be forwarded it to your application v1 server.
  • In deploying a new version v2 of your application, configure it to listen on port 127.0.0.1:5002.
  • Change the router configuration such that it now forwards traffic to 127.0.0.1:5002. Then tell the router to reload its configuration.
  • Now when your users make new requests to your router, they will be forwarded to your application v2 server.
  • You can safely shut down v1 once it stops receiving traffic. If there are issues with v2 you can revert back to v1 by reverting your router configuration, so keeping v1 running in the background has its benefits.

This is a simplified, high-level overview. (You should prefer unix sockets over the loopback interface, for example.) This kind of deployment is typically referred to as a canary or blue-green deployment.

huangapple
  • 本文由 发表于 2017年1月29日 02:25:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/41913240.html
匿名

发表评论

匿名网友

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

确定