关闭 mongodb 出错: Error: shutdown failed: not authorized

开启认证功能之后,出现了不能关闭数据库的现象,报错如下:

点击(此处)折叠或打开

  1. Error: assert failed : unexpected error: Error: shutdownServer failed: not authorized on admin to execute command { shutdown: 1.0 }

开启的操作是在/etc/mongo.conf,添加如下设置:

点击(此处)折叠或打开

  1. security:
  2.   authorization: enabled

从报错内容上看是权限不够,但不明了为什么,因为已经使用的超级用户权限:

点击(此处)折叠或打开

  1. {
  2.     "_id" : "admin.myUserAdmin",
  3.     "user" : "myUserAdmin",
  4.     "db" : "admin",
  5.     "roles" : [
  6.         {
  7.             "role" : "userAdminAnyDatabase",
  8.             "db" : "admin"
  9.         },
  10.         {
  11.             "role" : "dbOwner",
  12.             "db" : "admin"
  13.         }
  14.     ]
  15. }

经过查询错误解决办法,了解到是集群管理权限不够,添加相应权限之后就可以解决问题,变更用户权限如下:

点击(此处)折叠或打开

  1. > db.updateUser(
  2. ... "myUserAdmin",
  3. ... {
  4. ... roles : [
  5. ... {"role" : "userAdminAnyDatabase","db" : "admin"},
  6. ... {"role" : "dbOwner","db" : "admin"},
  7. ... {"role" : "clusterAdmin", "db": "admin"}
  8. ... ]
  9. ... }
  10. ... )

成功关闭数据库系统:

点击(此处)折叠或打开

  1. > db.shutdownServer({shutdown: 1, force: true})
  2. 2015-12-31T11:19:35.461+0800 I NETWORK DBClientCursor::init call() failed
  3. server should be down...
  4. 2015-12-31T11:19:35.463+0800 I NETWORK trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
  5. 2015-12-31T11:19:35.464+0800 I NETWORK reconnect 127.0.0.1:27017 (127.0.0.1) ok
  6. 2015-12-31T11:19:35.467+0800 I NETWORK Socket recv() errno:104 Connection reset by peer 127.0.0.1:27017
  7. 2015-12-31T11:19:35.467+0800 I NETWORK SocketException: remote: 127.0.0.1:27017 error: 9001 socket exception [RECV_ERROR] server [127.0.0.1:27017]
  8. 2015-12-31T11:19:35.467+0800 I NETWORK DBClientCursor::init call() failed
  9. > exit
  10. bye



参考链接:
用户权限更新:https://docs.mongodb.org/v3.0/reference/method/db.updateUser/
mongodb副本配置:http://www.linuser.com/thread-507-1-1.html
mongodb user roles:https://docs.mongodb.org/v3.0/reference/built-in-roles/
报错解决办法:http://stackoverflow.com/questions/13303685/stop-unknown-instance-mongodb-ubuntu

猜你喜欢

转载自blog.csdn.net/warrior_zhang/article/details/50503407