OpenShift MongoError:auth失败了如何解决?

时间:2015-03-30 04:52:31

标签: node.js mongodb mongoose openshift

编辑;附上我的app.js,我正在使用

git add app.js
git commit -m "updated app.js"
git push

命令从本地机器推送代码,我的app.js代码如下:

/*
*RESTfull server 
*/
//defining express middleware
var express=require('express');
//require mongoose, this middleware helps in modeling data for mongodb
var mongoose=require('mongoose');
//require passport, this middleware helps in authentiation
var passport=require('passport');
//require passport, this middleware parsing body
var bodyParser = require('body-parser');

var flash    = require('connect-flash');

//define port on which node app is gonna run
//var port     = process.env.PORT || 8000;
var server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080 ;
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1' ;

var app=express();


app.use(bodyParser.json());

app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
======================================================================
app.listen(server_port,server_ip_address);
console.log('The magic happens on port ' + 'http://'+server_ip_address+':'+server_port);

编辑: 我评论了所有mongodb连接代码,现在我的app.js有简单的expressjs代码,我仍然能看到命令的相同输出" rhc tail -a app",我不知道为什么nodejs catridge正在尝试连接到mongodb,尽管app.js中没有代码,是否有可能先前生成了日志并且显示了相同的日志?我可以清除日志文件并测试一次吗?有人能帮帮我吗。

我将nodejs(expressjs)应用程序部署到了openshift服务器。我遇到了mongoError" MongoError:auth失败",我正在为mongodb服务器提供凭据。 最初,当节点子进程启动时,它尝试连接到
" mongodb的://管理员:XXXXXX @ IP:端口"但它应该连接到" mongodb:// admin:XXXXXX @ ip:port / admin"凭据驻留在admin.system.users集合中。 我正在使用mongoose连接到mongoDB所以我改变了我的mongoose连接 mongoose.connect(mongodb的://管理员:XXXXXX @ IP:端口/管理员);但是我仍然看到子进程正在尝试连接到这个URL" mongodb:// admin:XXXXXX @ ip:port",但是稍后它连接到正确的集合,我可以看到控制台输出以下代码。



  mongoose.connection.once('connected', function() {
    console.log("Connected to database G")
  });




我测试了几条路线,它们工作正常。我想了解它为什么表现如此,我可以忽略这个错误,或者我该如何解决这个问题?

提前致谢。

2 个答案:

答案 0 :(得分:0)

您应该使用process.env.OPENSHIFT_MONGODB_DB_URL而不是形成自己的网址。此环境变量具有以下格式:

mongodb://admin:LX3eZCP6yxxx@123e4b9a5973ca07ca00002f-appname.rhcloud.com:12345/

答案 1 :(得分:0)

附上我的" rhc tail -a app" commad,



==> app-root/logs/nodejs.log-20150328020443 <==
DEBUG: Starting child process with 'node app.js'
mongodb://admin:pass@550f3e705973cab149000009-app.rhcloud.com:59281/

mongodb://admin:pass@550f3e705973cab149000009-app.rhcloud.com:59281/

The magic happens on port http://127.9.17.129:8080
/var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/runtime/repo/node_modules/m
ongoose/node_modules/mongodb/lib/mongodb/connection/base.js:246
        throw message;
              ^
MongoError: auth fails
    at Object.toError (/var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/runt
ime/repo/node_modules/mongoose/node_modules/mongodb/lib/mongodb/utils.js:114:11)

    at /var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/runtime/repo/node_mo
dules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1194:31

==> app-root/logs/nodejs.log-20150327071155 <==
    at EventEmitter.emit (events.js:98:17)
DEBUG: Program node app.js exited with code 8
DEBUG: Starting child process with 'node app.js'
mongodb://admin:pass@550f3e705973cab149000009-app.rhcloud.com:59281/

mongodb://admin:pass@550f3e705973cab149000009-app.rhcloud.com:59281/

The magic happens on port http://127.9.17.129:8080
/var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/runtime/repo/node_modules/m
ongoose/node_modules/mongodb/lib/mongodb/connection/base.js:246
        throw message;
              ^
MongoError: auth fails

==> app-root/logs/nodejs.log <==
DEBUG:   program 'app.js'
DEBUG:   --watch '/var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/data/.nod
ewatch'
DEBUG:   --ignore 'undefined'
DEBUG:   --extensions 'node|js|coffee'
DEBUG:   --exec 'node'
DEBUG: Starting child process with 'node app.js'
DEBUG: Watching directory '/var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/
data/.nodewatch' for changes.
admin:pass@550f3e705973cab149000009-app.rhcloud.com:59281
The magic happens on port http://127.9.17.129:8080
Connected to database G

==> app-root/logs/haproxy.log <==
[WARNING] 087/140540 (417258) : Server express/local-gear is UP, reason: Layer7
check passed, code: 200, info: "HTTP status check returned code <3C>200<3E>", ch
eck duration: 1ms. 1 active and 0 backup servers online. 0 sessions requeued, 0
total in queue.
[WARNING] 088/001408 (417258) : Server express/local-gear is DOWN, reason: Layer
4 connection problem, info: "Connection refused", check duration: 0ms. 0 active
and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[ALERT] 088/001408 (417258) : proxy 'express' has no server available!
[WARNING] 088/002019 (417258) : Server express/local-gear is UP, reason: Layer7
check passed, code: 200, info: "HTTP status check returned code <3C>200<3E>", ch
eck duration: 29ms. 1 active and 0 backup servers online. 0 sessions requeued, 0
 total in queue.
[WARNING] 088/110018 (417258) : Server express/local-gear is DOWN, reason: Layer
4 connection problem, info: "Connection refused", check duration: 0ms. 0 active
and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[ALERT] 088/110018 (417258) : proxy 'express' has no server available!
[WARNING] 088/110112 (417258) : Server express/local-gear is UP, reason: Layer7
check passed, code: 200, info: "HTTP status check returned code <3C>200<3E>", ch
eck duration: 1ms. 1 active and 0 backup servers online. 0 sessions requeued, 0
total in queue.
[WARNING] 088/110502 (417258) : Server express/local-gear is DOWN, reason: Layer
4 connection problem, info: "Connection refused", check duration: 0ms. 0 active
and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
[ALERT] 088/110502 (417258) : proxy 'express' has no server available!
[WARNING] 088/110556 (417258) : Server express/local-gear is UP, reason: Layer7
check passed, code: 200, info: "HTTP status check returned code <3C>200<3E>", ch
eck duration: 1ms. 1 active and 0 backup servers online. 0 sessions requeued, 0
total in queue.

==> app-root/logs/nodejs.log-20150328074316 <==
The magic happens on port http://127.9.17.129:8080
/var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/runtime/repo/node_modules/m
ongoose/node_modules/mongodb/lib/mongodb/connection/base.js:246
        throw message;
              ^
MongoError: auth fails
    at Object.toError (/var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/runt
ime/repo/node_modules/mongoose/node_modules/mongodb/lib/mongodb/utils.js:114:11)

    at /var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/runtime/repo/node_mo
dules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1194:31
    at /var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/runtime/repo/node_mo
dules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1903:9
    at Server.Base._callHandler (/var/lib/openshift/550f3c0ffcf933066f0001b8/app
-root/runtime/repo/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connec
tion/base.js:453:41)
    at /var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/runtime/repo/node_mo
dules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:487:18

==> app-root/logs/haproxy_ctld.log <==
I, [2015-03-22T18:06:38.808186 #415579]  INFO -- : Starting haproxy_ctld
I, [2015-03-27T14:20:21.556898 #15736]  INFO -- : Starting haproxy_ctld
I, [2015-03-29T12:18:29.365873 #417278]  INFO -- : Starting haproxy_ctld
I, [2015-03-29T12:18:37.485326 #417532]  INFO -- : Starting haproxy_ctld

==> app-root/logs/nodejs.log-20150323084556 <==
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/
runtime/repo/app.js:43:16)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
DEBUG: Program node app.js exited with code 8

==> app-root/logs/nodejs.log-20150328012640 <==
    at /var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/runtime/repo/node_mo
dules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1194:31
    at /var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/runtime/repo/node_mo
dules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1903:9
    at Server.Base._callHandler (/var/lib/openshift/550f3c0ffcf933066f0001b8/app
-root/runtime/repo/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connec
tion/base.js:453:41)
    at /var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/runtime/repo/node_mo
dules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:487:18
    at MongoReply.parseBody (/var/lib/openshift/550f3c0ffcf933066f0001b8/app-roo
t/runtime/repo/node_modules/mongoose/node_modules/mongodb/lib/mongodb/responses/
mongo_reply.js:68:5)
    at null.<anonymous> (/var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/ru
ntime/repo/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/ser
ver.js:445:20)
    at EventEmitter.emit (events.js:95:17)
    at null.<anonymous> (/var/lib/openshift/550f3c0ffcf933066f0001b8/app-root/ru
ntime/repo/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/con
nection_pool.js:207:13)
    at EventEmitter.emit (events.js:98:17)
DEBUG: Program node app.js exited with code 8
&#13;
&#13;
&#13;