零停机部署Node.js应用程序 [英] Zero downtime deployment Nodejs application

查看:151
本文介绍了零停机部署Node.js应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Nodejs应用程序,其中包括用于正常运行时间的群集和用于错误处理的域.

I have a Nodejs application that included clustering for being uptime and domain for error handling.

现在,为了实现零停机时间部署,我有一条指令,但是需要帮助将该指令转换为Nodejs代码(请给我一个示例).

Now for achieving zero downtime deployment, I have an instruction but I need help to convert this instruction to Nodejs code (I need an example for it please).

这是指令:

  1. 当master启动时,给它一个指向工作者代码的符号链接.
  2. 部署新代码后,更新符号链接
  3. 向主人发出信号:派遣新工人!
  4. 马特告诉老工人关闭,从新代码中派遣新工人.
  5. 重要进程永不停止运行

说明来源->幻灯片编号39

Instruction source -> slide number 39

推荐答案

对于100%的正常运行时间,无论您使用哪种语言,道路都差不多:

For 100% uptime the road is more or less the same regardless of the language you are using:

  • 将会话令牌存储在数据库中,而不是存储在内存中的数组中.交换版本后,这将允许用户保持登录状态.

  • Store your session tokens in a database rather than in an in-memory array or something. This will allow users to stay logged-in after you swap versions.

在Docker容器中运行服务器

Run your server inside a Docker container

当您需要运行新的服务器版本时,使用代理来处理交换容器.

Use a proxy to handle swapping containers when you need to run a new server version.

我写了 easy-deploy 来处理这些问题,因此我不需要担心每次都要设置代理.

I wrote easy-deploy to handle exactly that, so that I wouldn't need to worry about setting up the proxy every time.

部署版本1

easy-deploy -p 80:80 -v some/path:other/path my-image:1

要部署新版本,只需运行带有更新标签名称的命令

To deploy a new version just run the command with the updated tag name

easy-deploy -p 80:80 -v some/path:other/path my-image:2

代理已处理完毕. my-image:1将替换为my-image:2,而不会丢弃任何请求.

The proxy is taken care of. my-image:1 will be replaced by my-image:2 without letting any request drop.

这篇关于零停机部署Node.js应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆