[英]How to update running Node.js servers?
As far as I understand, a Node.js server is basically a JavaScript file, run by the node
executable. 据我所知,Node.js服务器基本上是一个JavaScript文件,由
node
可执行文件运行。 Is it possible to update this file without stopping request handling? 是否可以在不停止请求处理的情况下更新此文件?
I guess the node executable must be stopped for this, so I think I should use a reverse proxy. 我想必须为此停止节点可执行文件,所以我想我应该使用反向代理。 For example:
例如:
Is this a valid approach? 这是一种有效的方法吗? How can such a version update be done automatically on multiple server machines (accessible from the same LAN)?
如何在多台服务器计算机上自动完成此类版本更新(可从同一LAN访问)?
A different "pure-node" solution is to use the built-in cluster module: 一个不同的“纯节点”解决方案是使用内置的集群模块:
Your code runs as one cluster-client (of many). 您的代码作为一个集群客户端运行(许多)。 A cluster-server process binds to the port and does automatic load-balancing between clients.
集群服务器进程绑定到端口,并在客户端之间进行自动负载平衡。 When you've changed the code, you can send a signal to the cluster-server and it will gracefully restart your clients, without dropping any existing connections.
更改代码后,您可以向群集服务器发送信号,它将正常地重新启动客户端,而不会丢弃任何现有连接。
Here are some projects that can do the cluster-server management for you: 以下是一些可以为您执行集群服务器管理的项目:
Advantages: 好处:
Basically, what you can (should) do is the following: 基本上,你可以(应该)做的是以下内容:
When you need to update your system, shut down one of the two Node.js instances, update it, and restart it. 当您需要更新系统时,请关闭其中一个Node.js实例,更新它并重新启动它。 Then do the same with the other.
然后对另一个做同样的事情。
Basically, this should do it. 基本上,这应该做到这一点。
The downside is that you are potentially running different versions of your application for a small amount of time concurrently, and your database (eg) needs to be able to catch up with this. 缺点是您可能会在很短的时间内同时运行不同版本的应用程序,并且您的数据库(例如)需要能够赶上这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.