我正在嘗試向我的MongoDB添加授權。我正在Linux上使用MongoDB 2.6.1進行所有這些操作。我的mongod.conf文件為舊的兼容格式(這是安裝過程中附帶的格式)。1)我按照(3)所述創建了管理員用戶http://docs.mongodb.org/manual/tutorial/add-user-administrator/2)然后我通過取消注釋此行來編輯mongod.confauth = true3)最后,我重新啟動了mongod服務,并嘗試登錄:/usr/bin/mongo localhost:27017/admin -u sa -p pwd4)我可以連接,但連接時會說。MongoDB shell version: 2.6.1connecting to: localhost:27017/adminWelcome to the MongoDB shell!The current date/time is: Thu May 29 2014 17:47:16 GMT-0400 (EDT)Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }5)現在看來,sa我創建的該用戶完全沒有權限。root@test02:~# mcMongoDB shell version: 2.6.1connecting to: localhost:27017/adminWelcome to the MongoDB shell!The current date/time is: Thu May 29 2014 17:57:03 GMT-0400 (EDT)Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }[admin] 2014-05-29 17:57:03.011 >>> use adminswitched to db admin[admin] 2014-05-29 17:57:07.889 >>> show collections2014-05-29T17:57:10.377-0400 error: { "$err" : "not authorized for query on admin.system.namespaces", "code" : 13} at src/mongo/shell/query.js:131[admin] 2014-05-29 17:57:10.378 >>> use testswitched to db test[test] 2014-05-29 17:57:13.466 >>> show collections2014-05-29T17:57:15.930-0400 error: { "$err" : "not authorized for query on test.system.namespaces", "code" : 13} at src/mongo/shell/query.js:131[test] 2014-05-29 17:57:15.931 >>>問題是什么?我將整個過程重復了3次,我認為我按照MongoDB文檔中的說明進行了所有操作。但這是行不通的。我期望該sa用戶有權執行任何操作,以便他可以隨后創建其他用戶并為他們提供更具體的權限。
3 回答

夢里花落0921
TA貢獻1772條經驗 獲得超6個贊
我也為相同的問題scratch之以鼻,在添加第一個管理員用戶時,將角色設置為root,一切正常。
use admin
db.createUser(
{
user: 'admin',
pwd: 'password',
roles: [ { role: 'root', db: 'admin' } ]
}
);
exit;
如果已經創建了admin用戶,則可以這樣更改角色:
use admin;
db.grantRolesToUser('admin', [{ role: 'root', db: 'admin' }])
有關完整的身份驗證設置的參考,請參閱經過數小時的互聯網研究后編寫的步驟。
- 3 回答
- 0 關注
- 965 瀏覽
添加回答
舉報
0/150
提交
取消