2015-10-07 64 views
3

我剛剛爲mongodb實施了auth,在db'admin'中有一個用戶'admin' 和db'mydb'中的'appadmin'都工作正常。下面 是我的數據庫身份驗證設置:運行mongostat問題啓用mongodb

use admin 
db.auth(‘’, ‘’) 
db.getUsers() 
[ 
    { 
     "_id" : "admin.admin", 
     "user" : "admin", 
     "db" : "admin", 
     "roles" : [ 
      { 
       "role" : "userAdminAnyDatabase", 
       "db" : "admin" 
      }, 
      { 
       "role" : "clusterMonitor", 
       "db" : "admin" 
      } 
     ] 
    } 
] 


use mydb 
db.auth() 
db.getUsers() 

    { 
     "_id" : "mydb.appadmin", 
     "user" : "mydb", 
     "db" : "mydb", 
     "roles" : [ 
      { 
       "role" : "readWrite", 
       "db" : "mydb" 
      }, 
      { 
       "role" : "userAdmin", 
       "db" : "mydb" 
      } 
     ] 
    } 
]. 

如果我運行下面,

mongostat --username=admin --password=mypassword --authenticationDatabase=admin 
insert query update delete getmore command flushes mapped vsize res faults qr|qw ar|aw netIn netOut conn  time 
    *0 *0  *0  *0  0  1|0  0 240.0M 678.0M 91.0M  0 0|0 0|0 79b 10k 1 11:49:18 
    *0 *0  *0  *0  0  1|0  0 240.0M 678.0M 91.0M  0 0|0 0|0 79b 10k 1 11:49:19 
    *0 *0  *0  *0  0  1|0  0 240.0M 678.0M 91.0M  0 0|0 0|0 79b 10k 1 11:49:20 

但是當我運行

* mongostat --username=appadmin --password=mypassword --authenticationDatabase=mydb 

     Failed: not authorized on admin to execute command { serverStatus: 1, recordStats: 0 }, 

於是,我就在MYDB添加角色 'clusterMonitor' 。

db.updateUser(「appadmin」, {roles: [{role: "readWrite", db: 「mydb」}, {role: "userAdmin", db: 「mydb」}, {role: "clusterMonitor", db: 「mydb」}]}) 
E QUERY Error: Updating user failed: No role named [email protected] 

在啓用auth的mongoldb中執行mongostat的最佳方法是什麼?請幫我解決問題或提出最佳的身份驗證設置。 注:我的MongoDB版本3.0.6

回答

3

我終於得到了解決,我增加更多的角色來管理數據庫,

use admin 
db.getUsers() 

    { 
     "_id" : "admin.admin", 
     "user" : "admin", 
     "db" : "admin", 
     "roles" : [ 
      { 
       "role" : "userAdminAnyDatabase", 
       "db" : "admin" 
      }, 
      { 
       "role" : "readWriteAnyDatabase", 
       "db" : "admin" 
      }, 
      { 
       "role" : "dbAdminAnyDatabase", 
       "db" : "admin" 
      }, 
      { 
       "role" : "clusterAdmin", 
       "db" : "admin" 
      }, 
      { 
       "role" : "clusterMonitor", 
       "db" : "admin" 
      } 
     ] 
    } 
] 

和運行mongostat --username = --password管理=輸入mypassword --authenticationDatabase = admin,修復問題

+0

會''「角色」:「根」,....「完成同樣的事情? – ds011591

+0

看起來'clusterMonitor'是運行mongostat的關鍵。 –

+0

我不明白。你提到'mongostat'失敗了'appadmin',但給了'admin'用戶的解決方案?你可以將輸出粘貼到'mongostat --username = appadmin --password = mypassword --authenticationDatabase = mydb' – deppfx