简体   繁体   English

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

[英]Mongo Authentication Error When Connecting to MMS ReplicaSet

I deployed and manage my MongoDB instances on the server using MongoDB Management Service (MMS) and I have deployed a replica set. 我使用MongoDB管理服务(MMS)在服务器上部署和管理了我的MongoDB实例,并且已经部署了副本集。 I have also made sure that I added a user with the required permissions in the "Authorisation & Users" tab as shown in the image below. 我还确保在“授权和用户”选项卡中添加了具有所需权限的用户,如下图所示。

授权与用户

When I log into my server and run the command to check if the user has been added it shows that they have been authenticated because it returns 1. 当我登录服务器并运行命令以检查是否已添加用户时,它表明他们已通过身份验证,因为它返回1。

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

I have a node application that connects to mongodb using mongoose and this is the url format that I use to connect: 我有一个使用mongoose连接到mongodb的节点应用程序,这是我用来连接的url格式:

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

The issue that I am having is that when I start the Node application I get this error: 我遇到的问题是,当我启动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)

I have also attached my requested logs from the server that retrieved from MMS. 我还附加了从MMS检索到的服务器请求的日志。 I can see an authentication error but all the changes that I make don't seem to alter this error. 我可以看到身份验证错误,但是我所做的所有更改似乎都无法改变此错误。

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

I have deployed and connected to a mongodb database with an instance that I was managing myself without mms so I have a feeling that I am missing or have left out to allow me to connect to a mongodb instance managed by mms. 我已经部署了一个实例,并且该实例已连接到mongodb数据库并已连接到该实例,而我没有mms来管理自己,因此我感到自己丢失了或者被遗忘了,无法连接到mms管理的mongodb实例。

My automation agent, backup agent and monitoring agent are healthy too. 我的自动化代理,备份代理和监视代理也很健康。

Ok, so I finally got this working after almost pulling my hair out. 好的,所以在几乎拔出头发后,我终于可以正常工作了。 The first thing I did was made sure that all my node modules were up to date by running 我要做的第一件事是通过运行确保所有节点模块都是最新的

$ npm update
$ npm install

Once that was complete I modified my connection url to include the urls to my other mongo instances in the replica set. 完成此操作后,我修改了我的连接URL,以将其URL包含在副本集中的其他mongo实例中。 I did this because according to the mongodb documentation one needs to specify the other nodes in order to connect to a replica set or else a standalone instance will be created. 我这样做是因为根据mongodb文档,一个人需要指定其他节点才能连接到副本集,否则将创建一个独立实例。

To complete my uri string I added the actual authentication database where my user credentials are stored. 为了完成我的uri字符串,我添加了存储用户凭证的实际身份验证数据库。 So in the end my connection uri looked like this: 所以最后我的连接uri看起来像这样:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 连接到 Heroku PostgreSQL 数据库时的身份验证错误 - Authentication error when connecting to Heroku PostgreSQL database 使用身份验证连接时猫鼬索引错误 - Mongoose index error when connecting with authentication 连接到特定 mongodb 数据库时的身份验证错误 - Authentication error when connecting to specific mongodb database 连接到 Mongo 数据库时出错。 错误的身份验证失败 heroku + atlas mongodb + stripi - Error connecting to the Mongo database. bad auth Authentication failed heroku + atlas mongodb + strapi 连接数据库时出错(mongo 和 nodejs) - Error in connecting database (mongo and nodejs) 如何设置有效的mongo副本集 - How to setup a valid mongo replicaset “连接数据库时出错。 错误:错误:找不到有效的replicaset实例服务器“ - “ERROR while connecting to database. Error: Error: No valid replicaset instance servers found” 仅在3台服务器中的2台连接到MongoDB Replicaset时,Node.js“身份验证失败” - Node.js “auth fail” when connecting to MongoDB Replicaset with only 2 out of the 3 servers up 与 postgres 数据库连接时的身份验证错误 - Authentication error in connecting with postgres database 从Node.js连接mongodb副本集,以将副本集用作故障转移 - Connecting mongodb replicaset from nodejs, to use replicaset as failover
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM