簡體   English   中英

Node.js 應用程序不會部署在 AWS Elastic BeanStalk 上,可能是因為缺少 PostgreSQL 安裝

[英]Node.js app won't deploy on AWS Elastic BeanStalk possibly due to missing PostgreSQL install

我們有以下 package.json 文件:

{
  "name" : "DecisionsConsole",
  "version" : "0.0.0",
  "private" : true,
  "scripts" : {
    "start" : "node app.js"
  },
  "dependencies" : {
    "express" : "4.0.0",
    "cookie-parser" : "1.1.0",
    "serve-favicon" : "2.0.0",
    "morgan" : "1.1.1",
    "body-parser" : "1.3.0",
    "express-session" : "1.2.1",
    "errorhandler" : "1.0.1",
    "ejs" : "1.0.0",
    "request" : "2.34.0",
    "async" : "0.4.0",
    "lodash" : "2.4.1",
    "socket.io" : "1.0.4",
    "moment" : "~2.5.1",
    "pg" : "2.11.1",
    "connect" : "2.14.3",
    "sql" : "0.37.0",
    "request-json" : "0.4.10",
    "simplesets" : "1.2.0",
    "grunt" : "0.4.4",
    "aws-sdk" : "2.0.0-rc.19",
    "webworker-threads" : "0.4.13",
    "indexof" : "*",
    "serve-index" : "1.6.1",
    "node-rest-client" : "0.8.0",
    "querystring" : "0.2.0",
    "xml2js" : "0.4.6",
    "msexcel-builder" : "0.0.2",
    "mime" : "1.3.4"
  },
  "devDependencies" : {
    "grunt-contrib-compress" : "~0.7.0",
    "grunt-contrib-compass" : "~0.7.2",
    "grunt-contrib-uglify" : "*",
    "nodeunit" : "*"
  }
}

我們正在使用基於運行 Node.js 的 64 位 Amazon Linux 2014.02 v1.0.1 的 AWS Elastic BeanStalk 環境。 它是一個較舊的環境而不是最新版本之一的原因是因為我們的某些軟件包與較新的 AWS 環境之間似乎存在沖突。

部署時出現錯誤Update environment operation is complete, but with errors. For more information, see troubleshooting documentation. Update environment operation is complete, but with errors. For more information, see troubleshooting documentation.

經過進一步調查,我們在eb-tools.log發現了這樣的錯誤:

 /bin/sh: pg_config: command not found gyp: Call to 'pg_config --libdir' returned 
 exit status 127. gyp ERR! configure error gyp ERR! stack Error: `gyp` failed with 
 exit code: 1 gyp ERR! stack at ChildProcess.onCpExit (/opt/elasticbeanstalk/node-
 install/node-v0.10.26-linux-x64/lib/node_modules/npm/node_modules/node-gyp/lib/
 configure.js:337:16) gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:
 98:17) gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:
 797:12) gyp ERR! System Linux 3.4.73-64.112.amzn1.x86_64 gyp ERR! command "node" "/
 opt/elasticbeanstalk/node-install/node-v0.10.26-linux-x64/lib/node_modules/npm/
 node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /tmp/deployment/
 application/node_modules/pg gyp ERR! node -v v0.10.26 gyp ERR! node-gyp -v v0.12.2 
 gyp ERR! not ok > webworker-threads@0.4.13 install /tmp/deployment/application/
 node_modules/webworker-threads > node-gyp rebuild make: Entering directory `/tmp/
 deployment/application/node_modules/webworker-threads/build' CXX(target) Release/
 obj.target/WebWorkerThreads/src/WebWorkerThreads.o 

我意識到它有點難以閱讀,但它都在eb-tools.log文件中的一行中。 經過一番挖掘,我發現了這一點: 在 ubuntu 上安裝 node-gyp 時出錯 但是,我不認為這是相關的。

經過進一步研究,我發現了這個: https : //github.com/briac/node-postgres/issues/684

這似乎是有道理的。 問題是——如何讓 AWS Elastic BeanStalk 自動安裝 PG?

它表明您沒有在彈性 beantalk 實例上安裝 postgres

  1. 從項目的根目錄創建一個.ebextensions文件夾。
  2. 使用package.config和以下內容創建一個文件

    packages: yum: postgresql93-devel: []

  3. 然后提交您的更改
  4. 最后使用eb deploy部署到彈性 beantalk

那你應該很好。

查看此鏈接了解更多http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html

我在 Elastic Beanstalk 中部署 Node+PostgreSQL 應用程序時遇到了各種問題。 首先,我收到上述消息更新環境操作已完成,但有錯誤。 有關更多信息,請參閱故障排除文檔,因此我不得不稍微清理一下代碼:在我的 IDE(AWS 自己的 Cloud9)中運行良好的東西在 EB 中不起作用。 例如,我在使用 bcrypt 時遇到了問題,我不得不用 bcrypt.js 替換它。 此外,我的 package.json 將 Node 包含在依賴項中,並觸發了錯誤。

在得到一個像樣的“eb create”之后,最終的答案是這些說明 花點時間跟隨他們,因為通常匆忙的試錯不太可能成功。 這是因為添加數據庫增加了一些復雜性,主要是由於安全組設置。

在這里,您將找到使用 PostgreSQL 數據庫(在前面的鏈接中提到)設置 Node.js 應用程序的完整演練。 您有一個 github 存儲庫,您可以克隆並自行安裝。

AWS 人員的這段視頻也有助於進一步了解 EB。

祝你好運!

接受的答案是給出直接的解決方案。 那挺好的。 但我強烈建議您在 elasticbeanstalk 中將 nodejs 應用程序作為 docker 運行。 這樣,應用程序在您部署的任何地方都以相同的方式運行,而且您會及早發現構建問題並修復它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM