> 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
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/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/15498/viewspace-2062668/