如何连接到mongodb的身份验证实例,它是复制分片集群的一个成员



为什么从mongos创建的帐户不能在副本实例上使用?
日志:

[conn165] SCRAM-SHA-1 authentication failed for wuyg on admin from client 127.0.0.1 ; UserNotFound: Could not find user wuyg@admin  

用户wuyg有以下角色:

"roles" : [ { "role" : "clusterAdmin", "db" : "admin" }, { "role" : "dbOwner", "db" : "admin" }, { "role" : "userAdminAnyDatabase", "db" : "admin" } ]  

,当我从mongos连接时,我可以使用wuyg帐户。

我的mongodb集群有3个配置实例,1个分片,这是一个3个成员的复制集群。版本:3.2.8

谢谢。

在mongoDB中,用户保存在admin.system.users集合中。您可以使用以下命令列出用户:

use admin
db.system.users.find()

每个ReplicaSet实例都有自己的管理数据库和单独的系统。用户

Mongos(shardedCluster)使用admin数据库保存在配置服务器上。

如果你想用同一个用户连接mongos和replicaSet,你必须在replicaSets和mongos上分别创建这个用户

如果你只有一个shard,最好使用简单的replicaSet配置。您可以在需要额外容量时将其转换为shardedCluster https://docs.mongodb.com/manual/tutorial/convert-replica-set-to-replicated-shard-cluster/.

最新更新