阅读背景:

将节点生产部署到AWS的当前最佳实践是什么

来源:互联网 

I'm evaluating nodejs for small portion of our web application where it seems like it would be a good fit. I know that node is young and moving fast, but it seems like it has finally gotten to the "ready for production category". However, googling around, most information I see on production deployments are a year old and still warn about how fragile node can be and can error out unexpectedly, followed by some solutions to restart. This doesn't scare me away by itself, but there seems to be lack of official word on "the right way" to put node out there reliably.

我正在为我们的Web应用程序的一小部分评估nodejs,它似乎很适合。我知道这个节点很年轻,而且移动速度很快,但它似乎终于进入了“准备生产类别”。然而,谷歌搜索周围,大多数信息我看到生产部署一岁,仍然警告脆弱的节点如何能和会意外出错了,其次是一些解决方案,以重新启动。这并不会让我感到害怕,但似乎缺乏关于“正确的方式”将官方放在那里的官方消息。

2 个解决方案

#1


4  

cluster seems to be a good option, although depending on your OS it might have poor load-balancing performance. A very simple version would be something like this:

群集似乎是一个不错的选择,虽然取决于您的操作系统,它可能具有较差的负载平衡性能。一个非常简单的版本将是这样的:

var cluster = require('cluster')

if(cluster.isMaster) {
  var i, worker, workers;
  for(i = 0;i < numWorkers;i++) {
    worker = cluster.fork();
    workers[worker.process.pid] = worker;
  }
  cluster.on("exit", function(deadWorker) {
    delete workers[deadWorker.process.pid];
    worker = cluster.fork();
    workers[worker.process.pid] = worker;
  });
}
else {
  //be a real server process
}

This is a nice option because it both gives you some stability by restarting dead processes, and gives you multiple processes that share the load. Note that cluster basically modifies server.listen so that workers are all listening to events coming from the master, which is doing the listening. This is where the "free" load-balancing comes from.

这是一个不错的选择,因为它通过重新启动死进程为您提供了一些稳定性,并为您提供了共享负载的多个进程。请注意,群集基本上修改了server.listen,以便工作人员都在监听来自主服务器的事件,该事件正在进行监听。这就是“免费”负载平衡的来源。

Cluster documentation can be found here: https://nodejs.org/api/cluster.html

可以在此处找到集群文档:https://nodejs.org/api/cluster.html

It may also be worth having the master process handle a couple of signals if you want to be able to trigger certain events, such as killing and restarting all the processes, or killing all the processes and shutting down.

如果您希望能够触发某些事件(例如终止并重新启动所有进程,或者终止所有进程并关闭),那么主进程可能需要处理几个信号。

#2


0  

I am currently in the process of taking a node.js application to production for a highly scale-able social media application. To create a non-trivial deployment solution I am currently using AWS Elastic Beanstalk. The node AWS documentation can be found here [https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.html].

我目前正在将node.js应用程序用于生产高度可扩展的社交媒体应用程序。为了创建一个非平凡的部署解决方案,我目前正在使用AWS Elastic Beanstalk。可以在此处找到节点AWS文档[https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.html]。

I have tried this in my test environments and although it works, it is not a simple or easy to follow process. In particular I have had some problems with configuration using the Virtual Private Clouds for my environments. Also, as the service is somewhat new, there isn't a lot of information and troubleshooting advice freely available - which could of course be fixed by purchasing support from Amazon.

我在我的测试环境中尝试了这一点,虽然它有效,但它并不是一个简单或易于遵循的过程。特别是我在使用虚拟私有云为我的环境配置时遇到了一些问题。此外,由于该服务有点新,因此没有大量的信息和故障排除建议可以免费获得 - 当然可以通过购买亚马逊的支持来解决。

An Elastic Beanstalk deployment does appear to provide you with the following:

Elastic Beanstalk部署似乎确实为您提供以下内容:

  • If you are eligible a free-tier development environment.
  • 如果您符合免费级开发环境的资格。

  • Scale-able EC2 deployment for node applications and node architectures.
  • 针对节点应用程序和节点体系结构的可扩展EC2部署。

  • Consistent deployment across environments (ie dev, test, uat , production).
  • 跨环境的一致部署(即开发,测试,uat,生产)。

  • Monitoring.
  • Repeat-ability and automation for deployments.
  • 部署的重复能力和自动化。


分享到: