mongoDB的db.shutdownServer()報錯的解決方法

chenfeng發表於2016-03-23
> use admin
switched to db admin
> db.auth('root','root');
1
> show dbs
admin  0.078GB
local  0.06GB
test   0.03GB


> db.shutdownServer();
assert failed : unexpected error: Error: shutdownServer failed: not authorized on admin to execute command { shutdown: 1.0 }     
Error: assert failed : unexpected error: Error: shutdownServer failed: not authorized on admin to execute command { shutdown: 1.0 }
    at Error (<anonymous>)
    at doassert (src/mongo/shell/assert.js:11:14)
    at assert (src/mongo/shell/assert.js:20:5)
    at DB.shutdownServer (src/mongo/shell/db.js:212:9)
    at (shell):1:4
.......................................


最後檢查發現是缺少hostManger的這個角色,這個角色具有shutdown的許可權。



                                                     clusterAdmin        角色:clusterManager, clusterMonitor, hostManager
                                 
                                                    clusterManager       AddShard,ApplicationMessage,CleanupOrphaned,FlushRouterConfig,
                                                                                 ListShards,RemoveShard,ReplSetConfigure,ReplSetGetStatus,
                                                                                 ReplSetStateChange,Resync,


 Cluster Administration Roles         clusterMonitor        connPoolStats,cursorInfo,getCmdLineOpts,getLog,getParameter,
                                                                               getShardMap,hostInfo,inprog,listDatabases,listShards,netstat,
                                                                               replSetGetStatus,serverStatus,shardingState,top
                                                                               collStats,dbStats,getShardVersion
                                                  hostManager          applicationMessage,closeAllDatabases,connPoolSync,cpuProfiler,
                                                                              diagLogging,flushRouterConfig,fsync,invalidateUserCache,killop,
                                                                              logRotate,resync,setParameter,shutdown,touch,unlock 


賦予hostManager許可權:
> db.grantRolesToUser( "admin" , [ { role: "hostManager", db: "admin" } ])
> db.getName()
admin
> show tables;
system.indexes
system.users
system.version
> db.system.users.find()
{ "_id" : "admin.admin", "user" : "admin", "db" : "admin", "credentials" : { "MONGODB-CR" : "9f3121efccbe3fef09a799d5e63077c2" }, "roles" : [ { "role" : "readWriteAnyDatabase", "db" : "admin" }, { "role" : "readAnyDatabase", "db" : "admin" }, { "role" : "hostManager", "db" : "admin" }, { "role" : "userAdminAnyDatabase", "db" : "admin" } ] }
{ "_id" : "test.test", "user" : "test", "db" : "test", "credentials" : { "MONGODB-CR" : "e78333b96cbdc20a67432095f4741222" }, "roles" : [ { "role" : "dbOwner", "db" : "test" } ] }
> db.shutdownServer()
2016-01-26T10:18:30.064+0800 DBClientCursor::init call() failed
server should be down...
2016-01-26T10:18:30.066+0800 trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2016-01-26T10:18:30.067+0800 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-01-26T10:18:30.067+0800 reconnect 127.0.0.1:27017 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2062668/,如需轉載,請註明出處,否則將追究法律責任。

相關文章