简体   繁体   English

有没有人成功使用Amazon OpsWorks部署节点(快速)应用程序?

[英]Has anyone been successful deploying a node (express) app with Amazon OpsWorks?

As the title suggested, I've been playing around deploying apps with Amazons new OpsWorks management system, however I haven't been able to figure out how to get the node server to start running on the instance. 正如标题所示,我一直在使用Amazons新的OpsWorks管理系统来部署应用程序,但是我无法弄清楚如何让节点服务器开始在实例上运行。 From the ports the application layers have access too I assume I need be listening on port 80, however I feel that the problem is that the correct file isn't being started. 从端口应用程序层也可以访问我假设我需要在端口80上侦听,但我觉得问题是没有正确的文件被启动。

Similar to a Procfile on Heroku, is there a special start-script type file that needs to be included for OpsWorks to start it properly? 与Heroku上的Procfile类似,是否需要包含一个特殊的启动脚本类型文件,以便OpsWorks正确启动它?

Note that I don't have experience with Chef yet, so I'm hoping to get it working with the default options, ie not writting a custom Chef recipe to do it. 请注意,我还没有使用Chef的经验,因此我希望能够使用默认选项,即不编写自定义Chef配方来完成它。

The amount of time I spent on this is embarrassing, but I will share anyway in hopes of saving other people the hours of their lives that would otherwise be stolen by Amazon. 我花在这上面的时间是令人尴尬的,但无论如何我都会分享,希望能挽救其他人的生命时间,否则亚马逊会偷走他们的生命。

  • To answer your question, yes, I did get my node/express application running. 要回答你的问题,是的,我确实让我的节点/快速应用程序运行。
  • In case you were using any kind of process.env method of choosing your port number, change your listening port to 80 (or 443 if appropriate). 如果您使用任何类型的process.env选择端口号的方法,请将您的侦听端口更改为80(如果适用,则更改为443)。
  • Most importantly, Amazon doesn't care what your main file is. 最重要的是,亚马逊并不关心您的main文件是什么。 Rename it server.js and have it in the root directory of your application. 将其重命名为server.js并将其放在应用程序的根目录中。 That is the file that monit tries to run. 这是monit尝试运行的文件。

Hopefully that helps. 希望这会有所帮助。 If it doesn't, or if all of that is obvious, I apologize for my silliness and blame lack of sleep. 如果没有,或者所有这一切都是显而易见的,我为我的愚蠢和责备缺乏睡眠道歉。 :) :)

Great answer from ZachRabbit. ZachRabbit的答案很棒。 I'd just like to add that OpsWorks now supports setting of environment variables (ie process.env.PORT) for the deployed application process. 我想补充一点,OpsWorks现在支持为部署的应用程序进程设置环境变量(即process.env.PORT)。

When you Add App (or edit) you can go ahead and set up an environment variable with a key of PORT and a value of 80 if you're using something like the following in your server.js: 添加应用程序(或编辑)时,如果您在server.js中使用以下内容,则可以继续使用PORT键和值80设置环境变量:

!/usr/bin/env node
var debug = require('debug')('my-app');
var app = require('app');

app.set('port', process.env.PORT || 3000);

var server = app.listen(app.get('port'), function() {
  debug('Express server listening on port ' + server.address().port);
});

More information on the setting of the environment variables can be found here: 有关环境变量设置的更多信息,请访问:

http://docs.aws.amazon.com/opsworks/latest/userguide/apps-environment-vars.html http://docs.aws.amazon.com/opsworks/latest/userguide/apps-environment-vars.html

Ensuring that the filename was server.js and setting the environment variable PORT to 80 worked like a champ for me. 确保文件名是server.js并将环境变量PORT设置为80对我来说就像一个冠军。

Just copying the AWS OpsWorks page for configuring the node.js app: 只需复制AWS OpsWorks页面即可配置node.js应用程序:

"By default we expect your Node.js app to listen on port 80. Furthermore, the file we pass to node has to be named "server.js" and should be located in your app's root directory." “默认情况下,我们希望您的Node.js应用程序在端口80上侦听。此外,我们传递给节点的文件必须命名为”server.js“,并且应该位于应用程序的根目录中。”

Regards. 问候。

I played around this for a bit as well and hopefully my path to success will help someone. 我也在玩这个游戏,希望我的成功之路能够帮助别人。 Node.js usually needs elevated privileges to run on port 80 so I discovered that while naming the sample app app.js was fine, you need to modify line 2 of the default OpsWorks Node.js deploy chef recipe to use sudo: Node.js通常需要提升权限才能在端口80上运行,所以我发现虽然命名示例应用程序app.js很好,但您需要修改默认OpsWorks Node.js部署Chef recipe的第2行以使用sudo:

A bit off topic maybe, but I spent a couple of hours on this so I figured it's worth sharing: 有点偏离主题可能,但我花了几个小时就这个,所以我认为值得分享:

When setting up a Hapi.js server on OpsWorks, I had to ensure that I didn't use hostname localhost , but instead set it to 0.0.0.0 . OpsWorks上设置Hapi.js服务器时,我必须确保我没有使用主机名localhost ,而是将其设置为0.0.0.0 Otherwise it just kept failing silently. 否则它只是默默地失败了。

Hope that helps anyone. 希望能帮助任何人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM