好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

db.serverStatus()命名执行时报无权限问题的解决方法

1、问题描述

今天在执行 db.serverStatus() 命令时给出了 [ "errmsg" : "not authorized on admin to execute command { serverStatus: 1.0 }",] 的错误提示。

通过查询admin的权限已经是dbOwner的权限了,然后又陆续赋予了dbadmin等权限,问题仍旧存在。

最后找到了Mongodb的权限列表,赋予了root权限终于可以把问题给解决了,然后又测试了其他几个权限都不可以,这说明db.serverStatus是服务器级别的命令,需要mongodb的最高权限才能执行。

下面是问题处理的简单流程,分享给大家,以供参考。

2、错误内容

?

1

2

3

4

5

6

7

8

9

10

11

[root@ggnode2 ~]# mongo 10.130.170.112:27017/admin -u admin -p

MongoDB shell version: 3.2.8

Enter password :

connecting to : 10.130.170.112:27017/admin

MongoDB Enterprise >

MongoDB Enterprise > db.serverStatus()

{

   "ok" : 0,

   "errmsg" : "not authorized on admin to execute command { serverStatus: 1.0 }" ,

   "code" : 13

}

3、错误分析

从得到的错误内容可知,是由于admin没有执行 db.serverStatus() 命令的权限。

MongoDB Enterprise > use admin
switched to db admin
MongoDB Enterprise > show collections
system.users
system.version
MongoDB Enterprise > db.system.users.find()
{ "_id" : "admin.admin", "user" : "admin", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "BEN7SONYkewFMx3f67FNQw==", "storedKey" : "HjlvcjSpXpSKetcUbJyj350Xgjk=", "serverKey" : "k2WEf2cHGgg9n3tyEMJyuKaRt3U=" } }, "roles" : [{ "role" : "dbOwner", "db" : "admin" } ] }

根据查询结果可知,admin拥有dbOwner角色权限,而执行 db.serverStatus() 命令需要root角色权限。

4、问题处理:

经过查询表system.users表可知,需要为admin用户赋予root角色才能执行db.serverStatus()命令。

赋予角色权限的操作命令如下:

?

1

2

3

4

5

6

#授予角色权限

MongoDB Enterprise > db.grantRolesToUser( "admin" , [ { role: "root" , db: "admin" } ])

MongoDB Enterprise >

#取消角色权限

MongoDB Enterprise > db.revokeRolesFromUser( "admin" , [ { role: "root" , db: "admin" } ]

MongoDB Enterprise >

5、问题解决

赋予root角色权限之后,再执行 db.serverStatus() 命令就OK了,执行结果如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

MongoDB Enterprise > db.serverStatus()

MongoDB shell version: 3.2.8

connecting to : 10.130.170.112:27017/admin

{

   "host" : "ggnode2" ,

   "advisoryHostFQDNs" : [ ],

   "version" : "3.2.8" ,

   "process" : "mongod" ,

   "pid" : NumberLong(23155),

   "uptime" : 1470624,

   "uptimeMillis" : NumberLong(1470624043),

   "uptimeEstimate" : 1415522,

   "localTime" : ISODate( "2016-11-07T04:13:33.328Z" ),

   "asserts" : {

     "regular" : 0,

     "warning" : 0,

     "msg" : 0,

     "user" : 62,

     "rollovers" : 0

   },

   "connections" : {

     "current" : 1,

     "available" : 818,

     "totalCreated" : NumberLong(6025)

   },

   "extra_info" : {

     "note" : "fields vary by platform" ,

     "heap_usage_bytes" : 60437840,

     "page_faults" : 28

   },

   "globalLock" : {

     "totalTime" : NumberLong( "1470624234000" ),

     "currentQueue" : {

       "total" : 0,

       "readers" : 0,

       "writers" : 0

     },

     "activeClients" : {

       "total" : 8,

       "readers" : 0,

       "writers" : 0

     }

   },

   "locks" : {

… …

     "storage" : {

       "freelist" : {

         "search" : {

           "bucketExhausted" : NumberLong(0),

           "requests" : NumberLong(0),

           "scanned" : NumberLong(0)

         }

       }

     },

     "ttl" : {

       "deletedDocuments" : NumberLong(0),

       "passes" : NumberLong(24508)

     }

   },

   "ok" : 1

}

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对服务器之家的支持。

原文链接:http://forum.foxera测试数据/mongodb/topic/174/解决db-serverstatus-命名执行时报无权限的问题

查看更多关于db.serverStatus()命名执行时报无权限问题的解决方法的详细内容...

  阅读:25次