简体   繁体   English

未经命令授权:数据库管理员上的addShard

[英]Not authorized for command: addShard on database admin

I'm building a MongoDB cluster using shards of replica sets and have the first replica set setup and three config servers running (all on Linux servers) with a mongos instance running pointing to the three config servers, but when connecting to the mongos instance on the application server (on Windows Server 2012 Standard x64) via the mongo shell and issuing the sh.addShard() command as per the docs , I get the following response: 我正在使用副本集的碎片构建MongoDB集群,并具有第一个副本集设置和三台配置服务器(均在Linux服务器上)运行,而mongos实例正在运行,指向三台配置服务器,但是当连接到on上的mongos实例时应用程序服务器(在Windows Server 2012 Standard x64上)通过mongo shell并根据docs发出sh.addShard()命令,我得到以下响应:

> sh.addShard("rs1/xxx:xxx")
{
        "note" : "not authorized for command: addShard on database admin",
        "ok" : 0,
        "errmsg" : "unauthorized"
}

Does anyone know what I'm doing wrong? 有人知道我在做什么错吗? I'm running all Mongo instances using a keyfile for security. 我正在使用密钥文件运行所有Mongo实例,以确保安全。 The keyfile is a Windows compatible one as per these docs . 根据这些文档 ,密钥文件是Windows兼容的文件

My results: 我的结果:

If your data nodes use keyfile based authentication, all the mongod and mongos instances (data, config, etc) need to use --keyFile as well and point to an exact copy of the keyfile. 如果您的数据节点使用基于密钥文件的身份验证,则所有mongod和mongos实例(数据,配置等)也需要使用--keyFile并指向密钥文件的精确副本。

Secondly, make sure you "use admin" after connecting to config servers using mongos. 其次,使用mongos连接到配置服务器后,请确保您“使用管理员”。 If this doesn't get you there then add an admin user at the mongos prompt, authenticate with those credentials and try again. 如果仍然无法到达目的地,请在mongos提示符下添加一个管理员用户,使用这些凭据进行身份验证,然后重试。

I've since solved this. 从那以后我解决了这个问题。 It was because authentication was enabled by virtue of the keyfile and using the localhost connection wasn't enough to authenticate. 这是因为通过密钥文件启用了身份验证,并且使用localhost连接不足以进行身份​​验证。 After disabling keyfile usage across the cluster, creating an admin account and using that to connect, it worked. 在整个群集中禁用密钥文件使用,创建一个管理员帐户并使用该帐户进行连接之后,它就可以工作了。

in addition to bisharkha's answer, here is one more clue to use keyfile. 除了bisharkha的答案之外,还有另外一个使用密钥文件的线索。

after use admin command, also make sure you have authenticated with: db.auth("user", "passwd") use admin命令后,还请确保您已通过以下db.auth("user", "passwd")进行身份验证: db.auth("user", "passwd")

如果您为集合指定了错误的名称,也会发生这种情况。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM