打开换档节点+ mongodb无法启动

时间:2016-08-02 19:19:05

标签: node.js mongodb openshift

我正在尝试将Node 6.0服务器和mongo 3.2一起部署到openshift上。 我已经设法使用节点DIY盒式磁带创建一个应用程序,如下所示:http://cartreflect-claytondev.rhcloud.com/reflect?github=connyay/openshift-node-diy

并添加一个mongo DIY墨盒:https://raw.githubusercontent.com/icflorescu/openshift-cartridge-mongodb/master/metadata/manifest.yml

此外,我添加了.Openshift \ action_hooks文件,它们将npm install作为构建脚本的一部分进行调用。

现在到了奇怪的部分,在推送更改和依赖完成安装后,我得到正常的消息,说部署成功了。但是,我的服务器在尝试访问它时仍然返回503错误。我试着调用rhc tail来跟踪服务器启动过程中出了什么问题,但我得到的是来自mongodb的这个日志:

2016-08-02T10:24:41.848-0400 I STORAGE  [main] Engine custom option: cache_size=256M
2016-08-02T10:24:41.858-0400 I CONTROL  [initandlisten] MongoDB starting : pid=263740 port=27017 dbpath=/var/lib/openshift/57a0601f0c1e66334d000014/app-root/data/.mongodb/data 64-bit host=ex-std-node712.prod.rhcloud.com
2016-08-02T10:24:41.858-0400 I CONTROL  [initandlisten] db version v3.2.7
2016-08-02T10:24:41.858-0400 I CONTROL  [initandlisten] git version: 4249c1d2b5999ebbf1fdf3bc0e0e3b3ff5c0aaf2
2016-08-02T10:24:41.858-0400 I CONTROL  [initandlisten] allocator: tcmalloc
2016-08-02T10:24:41.858-0400 I CONTROL  [initandlisten] modules: none
2016-08-02T10:24:41.858-0400 I CONTROL  [initandlisten] build environment:
2016-08-02T10:24:41.858-0400 I CONTROL  [initandlisten]     distarch: x86_64
2016-08-02T10:24:41.858-0400 I CONTROL  [initandlisten]     target_arch: x86_64
2016-08-02T10:24:41.858-0400 I CONTROL  [initandlisten] options: { net: { bindIp: "127.7.166.130", unixDomainSocket: { enabled: false } }, storage: { dbPath: "/var/lib/openshift/57a0601f0c1e66334d000014/app-root/data/.mongodb/data", engine: "wiredTiger", wiredTiger: { engineConfig: { configString: "cache_size=256M" } } }, systemLog: { logAppend: true, logRotate: "reopen", quiet: true } }
2016-08-02T10:24:41.920-0400 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=8G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),cache_size=256M
2016-08-02T10:24:42.466-0400 I CONTROL  [initandlisten] 
2016-08-02T10:24:42.466-0400 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-08-02T10:24:42.466-0400 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-08-02T10:24:42.466-0400 I CONTROL  [initandlisten] 
2016-08-02T10:24:42.466-0400 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-08-02T10:24:42.466-0400 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-08-02T10:24:42.466-0400 I CONTROL  [initandlisten] 
2016-08-02T10:24:42.466-0400 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 350 processes, 1024 files. Number of processes should be at least 512 : 0.5 times number of files.
2016-08-02T10:24:42.466-0400 I CONTROL  [initandlisten] 
2016-08-02T10:24:42.473-0400 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/openshift/57a0601f0c1e66334d000014/app-root/data/.mongodb/data/diagnostic.data'
2016-08-02T10:24:42.515-0400 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-08-02T10:24:42.521-0400 I NETWORK  [initandlisten] waiting for connections on port 27017

后面跟着这个错误日志(显然是由节点抛出但是找不到文件:

> MyApp-API@0.1.0 start /var/lib/openshift/57a0601f0c1e66334d000014/app-root/runtime/repo
> NODE_ENV=development;DEBUG=*,-not_this,-morgan;node ./bin/www

Port 8080 is already in use

npm ERR! Linux 2.6.32-573.26.1.el6.x86_64
npm ERR! argv "/var/lib/openshift/57a0601f0c1e66334d000014/node-diy/bin/node/bin/node" "/var/lib/openshift/57a0601f0c1e66334d000014/node-diy/bin/node/bin/npm" "start"
npm ERR! node v5.11.1
npm ERR! npm  v3.8.6
npm ERR! code ELIFECYCLE
npm ERR! MyApp-API@0.1.0 start: `NODE_ENV=development;DEBUG=*,-not_this,-morgan;node ./bin/www`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the MyApp-API@0.1.0 start script 'NODE_ENV=development;DEBUG=*,-not_this,-morgan;node ./bin/www'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the MyApp-API package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     NODE_ENV=development;DEBUG=*,-not_this,-morgan;node ./bin/www
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs MyApp-API
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls MyApp-API
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /var/lib/openshift/57a0601f0c1e66334d000014/app-root/runtime/repo/npm-debug.log

我在这里失踪了什么?这里似乎没有任何真正的错误信息。它只是说我的scripts.start脚本失败了,有些人认为它可能是环境变量的东西,但我不确定哪些可能会像这样搞乱

修改

我还应该提一下,我已经将我的www应用设置设置为在可用时使用openshift变量:

var port = normalizePort(process.env.OPENSHIFT_NODEDIY_PORT || '3000');
app.set('port', port);

var ip = process.env.OPENSHIFT_NODEDIY_IP || localhost; //'192.168.1.16'
app.set('ip', ip);

和mongo连接:

var mongodb_connection_string = 'mongodb://localhost/' + db_name;
    //take advantage of openshift env vars when available:
    if(process.env.MONGODB_URL){
        mongodb_connection_string = process.env.MONGODB_URL + db_name;
    }

编辑2 我最终设法找到存储我得到的节点错误的日志文件,似乎rhc tail没有返回完整堆栈但只返回最后几行。整个日志实际上揭示了该问题的更多细节(参见上面编辑的错误)

1 个答案:

答案 0 :(得分:0)

所以我终于弄清楚出了什么问题。

似乎我的IDE(当前是webstorm)创建的默认节点项目被配置为监听端口,无论ip是什么,所以我的www脚本有这个:

var port = normalizePort(process.env.OPENSHIFT_NODEDIY_PORT || '3000');
app.set('port', port);

var ip = process.env.OPENSHIFT_NODEDIY_IP || localhost;
app.set('ip', ip);

/**
 * Create HTTP server.
 */

var server = http.createServer(app);

/**
 * Listen on provided port, on all network interfaces.
 */

server.listen(port);

所以在最后一行你看到我只是听端口并忽略ip,将最后一行改为

server.listen(port, ip);

解决了这个问题。