Amazon AWS EC2 Linux 上的 Node-gyp Connect-mongo

Node-gyp Connect-mongo on Amazon AWS EC2 Linux

我无法在我的 EC2 实例上安装 connect-mongo。与无法访问“/root/.node-gyp/0.10.40”的 node-gyp 有关——这很奇怪,因为安装的 Node 版本是 4.2.1。

文件夹“/root/.node-gyp/”甚至没有在系统上退出。那么为什么 node-gyp 会在那里找?

配置服务器时我先安装了Node 0.10.40,然后升级到4.2.1。

我们如何将 node-gyp 指向正确的目录?还是其他地方的问题?

登录成功 在本地主机上安装:

$ node --version
v4.2.1
$ npm --version
2.14.7

$ npm install connect-mongo --save
|
> kerberos@0.0.16 install /Users/username/Sites/adserver/node_modules/connect-mongo/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos
> node-gyp rebuild

  CXX(target) Release/obj.target/kerberos/lib/kerberos.o
  CXX(target) Release/obj.target/kerberos/lib/worker.o
  CC(target) Release/obj.target/kerberos/lib/kerberosgss.o
../lib/kerberosgss.c:509:13: warning: implicit declaration of function 'gss_acquire_cred_impersonate_name' is invalid in C99 [-Wimplicit-function-declaration]
        maj_stat = gss_acquire_cred_impersonate_name(&min_stat,
                   ^
1 warning generated.
  CC(target) Release/obj.target/kerberos/lib/base64.o
  CXX(target) Release/obj.target/kerberos/lib/kerberos_context.o
  SOLINK_MODULE(target) Release/kerberos.node
connect-mongo@0.8.2 node_modules/connect-mongo
├── depd@1.1.0
├── debug@2.2.0 (ms@0.7.1)
└── mongodb@2.0.47 (es6-promise@2.1.1, readable-stream@1.0.31, mongodb-core@1.2.20)

登录失败 在 EC2 Linux 上安装:

$ node --version
v4.2.1
$ npm --version
2.14.7

$ sudo npm install connect-mongo
\
> kerberos@0.0.16 install /home/ec2-user/apps/adserver/node_modules/connect-mongo/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos
> node-gyp rebuild

gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/0.10.40"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/ec2-user/apps/adserver/node_modules/connect-mongo/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/.node-gyp"
make: Entering directory `/home/ec2-user/apps/adserver/node_modules/connect-mongo/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build'
  CXX(target) Release/obj.target/kerberos/lib/kerberos.o
In file included from ../lib/kerberos.cc:1:0:
../lib/kerberos.h:5:27: fatal error: gssapi/gssapi.h: No such file or directory
 #include <gssapi/gssapi.h>
                           ^
compilation terminated.
make: *** [Release/obj.target/kerberos/lib/kerberos.o] Error 1
make: Leaving directory `/home/ec2-user/apps/adserver/node_modules/connect-mongo/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:820:12)
gyp ERR! System Linux 4.1.7-15.23.amzn1.x86_64
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/ec2-user/apps/adserver/node_modules/connect-mongo/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos
gyp ERR! node -v v0.10.40
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok 
npm WARN optional dep failed, continuing kerberos@0.0.16
connect-mongo@0.8.2 node_modules/connect-mongo
├── depd@1.1.0
├── debug@2.2.0 (ms@0.7.1)
└── mongodb@2.0.47 (readable-stream@1.0.31, es6-promise@2.1.1, mongodb-core@1.2.20)
[ec2-user@ip-172-31-9-139 adserver]$ 

问题不在于 gyp WARN EACCESS ... 消息。这只是一个警告,npm 可以继续使用解决方法。但要消除此警告消息,请参阅 .

问题在于:

./lib/kerberos.h:5:27: fatal error: gssapi/gssapi.h: No such file or directory
 #include <gssapi/gssapi.h>

我发现了这个 link 并且解决方案(在 Ubuntu/Debian 上)似乎是:

sudo apt-get install libkrb5-dev