连接到MMS ReplicaSet时出现Mongo身份验证错误

时间:2015-03-11 09:15:15

标签: node.js mongodb mongoose mongodb-mms

我使用MongoDB管理服务(MMS)在服务器上部署和管理我的MongoDB实例,并且我已部署了副本集。我还确保在"授权&中添加了具有所需权限的用户。用户"标签如下图所示。

Authorisation & Users

当我登录我的服务器并运行命令以检查是否已添加用户时,它显示已经过身份验证,因为它返回1.

$ use admin
$ db.auth('mbdb', 'xxxx')
$ 1

我有一个使用mongoose连接到mongodb的节点应用程序,这是我用来连接的url格式:

'url' : 'mongodb://mbdb:xxxx@localhost:27000/dbprod?replicaSet=ProdSet'

我遇到的问题是,当我启动Node应用程序时,我收到此错误:

> mobile-bulletin-node@0.0.1 start /var/TeamCity/buildAgent/work/d81f9c89b9a85a90
> node ./bin/www

{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version

/var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:246
    throw message;      
          ^
MongoError: auth failed
at Object.toError (/var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/utils.js:114:11)
at /var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1156:31
at /var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1890:9
at Server.Base._callHandler (/var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:448:41)
at /var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:481:18
at MongoReply.parseBody (/var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
at null.<anonymous> (/var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:439:20)
at emit (events.js:95:17)
at null.<anonymous> (/var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:201:13)
at emit (events.js:98:17)

我还从MMS检索到的服务器上附加了我请求的日志。我可以看到身份验证错误,但我所做的所有更改似乎都没有改变此错误。

2015-03-11T04:04:00.183-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42476 #6051 (6 connections now open)
2015-03-11T04:04:00.194-0500 I ACCESS   [conn6051] Successfully authenticated as principal mms-automation on admin
2015-03-11T04:04:00.697-0500 I NETWORK  [conn6049] end connection 159.8.163.164:42462 (5 connections now open)
2015-03-11T04:04:00.697-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42477 #6052 (6 connections now open)
2015-03-11T04:04:00.707-0500 I ACCESS   [conn6052] Successfully authenticated as principal __system on local
2015-03-11T04:04:03.158-0500 I ACCESS   [conn19] Successfully authenticated as principal mms-monitoring-agent on admin
2015-03-11T04:04:04.695-0500 I NETWORK  [conn6050] end connection 159.8.163.164:42468 (5 connections now open)
2015-03-11T04:04:04.695-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42486 #6053 (6 connections now open)
2015-03-11T04:04:04.705-0500 I ACCESS   [conn6053] Successfully authenticated as principal __system on local
2015-03-11T04:04:05.184-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42487 #6054 (7 connections now open)
2015-03-11T04:04:25.811-0500 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:49873 #6055 (8 connections now open)
2015-03-11T04:04:25.811-0500 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:49874 #6056 (9 connections now open)
2015-03-11T04:04:25.812-0500 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:49875 #6057 (10 connections now open)
2015-03-11T04:04:25.812-0500 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:49876 #6058 (11 connections now open)
2015-03-11T04:04:25.812-0500 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:49877 #6059 (12 connections now open)
2015-03-11T04:04:25.818-0500 I ACCESS   [conn6055]  authenticate db: dbprod { authenticate: 1, user: "mbdb", nonce: "xxx", key: "xxx" }
2015-03-11T04:04:25.818-0500 I ACCESS   [conn6056]  authenticate db: dbprod { authenticate: 1, user: "mbdb", nonce: "xxx", key: "xxx" }
2015-03-11T04:04:25.819-0500 I ACCESS   [conn6055] Failed to authenticate mbdb@dbprod with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document
2015-03-11T04:04:25.819-0500 I ACCESS   [conn6057]  authenticate db: dbprod { authenticate: 1, user: "mbdb", nonce: "xxx", key: "xxx" }
2015-03-11T04:04:25.819-0500 I ACCESS   [conn6058]  authenticate db: dbprod { authenticate: 1, user: "mbdb", nonce: "xxx", key: "xxx" }
2015-03-11T04:04:25.819-0500 I ACCESS   [conn6056] Failed to authenticate mbdb@dbprod with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document
2015-03-11T04:04:25.819-0500 I ACCESS   [conn6059]  authenticate db: dbprod { authenticate: 1, user: "mbdb", nonce: "xxx", key: "xxx" }
2015-03-11T04:04:25.819-0500 I ACCESS   [conn6057] Failed to authenticate mbdb@dbprod with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document
2015-03-11T04:04:25.819-0500 I ACCESS   [conn6058] Failed to authenticate mbdb@dbprod with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document
2015-03-11T04:04:25.819-0500 I ACCESS   [conn6059] Failed to authenticate mbdb@dbprod with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document
2015-03-11T04:04:25.823-0500 I NETWORK  [conn6059] end connection 127.0.0.1:49877 (11 connections now open)
2015-03-11T04:04:25.823-0500 I NETWORK  [conn6058] end connection 127.0.0.1:49876 (11 connections now open)
2015-03-11T04:04:25.823-0500 I NETWORK  [conn6056] end connection 127.0.0.1:49874 (11 connections now open)
2015-03-11T04:04:25.823-0500 I NETWORK  [conn6057] end connection 127.0.0.1:49875 (11 connections now open)
2015-03-11T04:04:25.823-0500 I NETWORK  [conn6055] end connection 127.0.0.1:49873 (7 connections now open)
2015-03-11T04:04:30.710-0500 I NETWORK  [conn6052] end connection 159.8.163.164:42477 (6 connections now open)
2015-03-11T04:04:30.710-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42495 #6060 (7 connections now open)
2015-03-11T04:04:30.720-0500 I ACCESS   [conn6060] Successfully authenticated as principal __system on local
2015-03-11T04:04:34.707-0500 I NETWORK  [conn6053] end connection 159.8.163.164:42486 (6 connections now open)
2015-03-11T04:04:34.707-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42501 #6061 (7 connections now open)
2015-03-11T04:04:34.717-0500 I ACCESS   [conn6061] Successfully authenticated as principal __system on local
2015-03-11T04:04:54.412-0500 I ACCESS   [conn19] Successfully authenticated as principal mms-monitoring-agent on admin
2015-03-11T04:04:54.414-0500 I QUERY    [conn19] assertion 13 not authorized for query on local.oplog.rs ns:local.oplog.rs query:{ $query: {}, $orderby: { $natural: 1 } }
2015-03-11T04:04:54.414-0500 I QUERY    [conn19]  ntoskip:0 ntoreturn:-1
2015-03-11T04:04:54.414-0500 I QUERY    [conn19] assertion 13 not authorized for query on local.oplog.rs ns:local.oplog.rs query:{ $query: {}, $orderby: { $natural: -1 } }
2015-03-11T04:04:54.414-0500 I QUERY    [conn19]  ntoskip:0 ntoreturn:-1
2015-03-11T04:05:00.724-0500 I NETWORK  [conn6060] end connection 159.8.163.164:42495 (6 connections now open)
2015-03-11T04:05:00.724-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42512 #6062 (7 connections now open)
2015-03-11T04:05:00.734-0500 I ACCESS   [conn6062] Successfully authenticated as principal __system on local
2015-03-11T04:05:04.718-0500 I NETWORK  [conn6061] end connection 159.8.163.164:42501 (6 connections now open)
2015-03-11T04:05:04.718-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42517 #6063 (7 connections now open)
2015-03-11T04:05:04.728-0500 I ACCESS   [conn6063] Successfully authenticated as principal __system on local

我已经部署并连接到一个mongodb数据库,其中包含我自己管理的实例,没有mms,所以我感觉我失踪了或者没有让我连接到由mms管理的mongodb实例。

我的自动化代理,备份代理和监控代理也很健康。

1 个答案:

答案 0 :(得分:1)

好的,所以我差点把头发拉出来后终于开始工作了。我做的第一件事是通过运行

确保我的所有节点模块都是最新的
$ npm update
$ npm install

一旦完成,我修改了我的连接URL,将url包含在副本集中的其他mongo实例中。我这样做是因为根据mongodb文档,需要指定其他节点才能连接到副本集,否则将创建一个独立的实例。

要完成我的uri字符串,我添加了存储用户凭据的实际身份验证数据库。所以最后我的连接uri看起来像这样:

'url' : 'mongodb://mbdb:xxxx@localhost:27000,localhost:27001,localhost:27002/dbprod?replicaSet=ProdSet&authSource=admin'