关闭mongodb并启用auth

时间:2013-12-19 20:51:33

标签: windows mongodb

我在我的本地Windows机器上设置了mongodb。我按照mongo文档中的说明设置了auth。我使用auth标志关闭并重新启动服务器。我使用“use admin”切换到admin db,然后使用db.auth。它让我登录,但当我尝试使用shutdown命令(db.shutdownServer)时,我被告知未经授权。如何关闭服务器(关闭cmd提示符除外)

1 个答案:

答案 0 :(得分:3)

我不理解你的问题中有关“使用db.auth”的内容,但一般来说,你需要以角色“clusterAdmin”http://docs.mongodb.org/manual/reference/user-privileges/#clusterAdmin的身份登录Mongo。这适用于我的系统,但我有一个LaunchDaemon运行的东西立即重新启动它,但重点是用户“rkuhar”可以从mongo shell中发出db.shutdownServer()命令,因为他的system.user记录在管理员数据库包含“clusterAdmin”角色。

bobk-mbp:DM_Server bobk$ mongo -p -u rkuhar localhost:27018/admin
MongoDB shell version: 2.4.6
Enter password: 
connecting to: localhost:27018/admin
dmReplSet:SECONDARY> db.shutdownServer();
Thu Dec 19 14:48:44.358 DBClientCursor::init call() failed
server should be down...
Thu Dec 19 14:48:44.363 trying reconnect to localhost:27018
Thu Dec 19 14:48:44.365 reconnect localhost:27018 failed couldn't connect to server localhost:27018
> 

这是我的用户“rkuhar”在管理数据库中的样子。

bobk-mbp:DM_Server bobk$ mongo -p -u userAdmin localhost/admin 
MongoDB shell version: 2.4.6
Enter password: 
connecting to: localhost/admin
> db.system.users.find( { user : 'rkuhar' } ).pretty();
{
    "_id" : ObjectId("526061a45cf44cef5b2ef011"),
    "pwd" : "097df10ea69d71d986fe5e94dbad77b1",
    "roles" : [
        "readWriteAnyDatabase",
        "dbAdminAnyDatabase",
        "clusterAdmin"
    ],
    "user" : "rkuhar"
}
> 
相关问题