mongoDB的db.shutdownServer()报错的解决方法

> 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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15498/viewspace-2062668/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值