【问题标题】:Open shift node + mongodb cant startOpenshift节点+mongodb无法启动
【发布时间】:2016-08-02 19:19:05
【问题描述】:

我正在尝试将 Node 6.0 服务器与 mongo 3.2 一起部署到 openshift 上。 我已经设法使用 Node 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 没有返回完整的堆栈,而只返回了最后几行。整个日志实际上揭示了有关该问题的更多详细信息(请参阅上面的编辑错误)

【问题讨论】:

  • 您的节点监听的地址和端口是否正确? Openshift 有一些你打算使用的环境变量
  • @MicheleRicciardi 看到我上面的编辑,这是你的意思吗?如果是的话,那就是
  • 是的,这些就是我所说的环境变量,你是否也用端口和 IP 调用 app.listen

标签: node.js mongodb openshift


【解决方案1】:

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

似乎我的 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);

修复了问题。

【讨论】:

    猜你喜欢
    • 2019-05-13
    • 1970-01-01
    • 2015-09-29
    • 2022-06-16
    • 2016-05-05
    • 1970-01-01
    • 1970-01-01
    • 2018-09-30
    • 1970-01-01
    相关资源
    最近更新 更多