mongodb授权使用mongotop

mongodb开启授权登录后,使用mongotop和mongostat等命令都需要进行相应角色授权。可使用内部角色进行授权,也可自建规则进行授权。此处介绍第二种,即自建规则。

1、切换到admin

use admin

2、创建规则

db.createRole({
    role: "mongotopRole",
    privileges: [{
        resource: { cluster: true },
        actions: [ "serverStatus", "top" ]
    }],
    roles: []
})

具体权限要求,可在官方文档查看。

Demo (mongotop):

​ 链接:https://docs.mongodb.com/manual/reference/program/mongotop/index.html

​ 其中Required Access中有提及,包括自建规则,以及符合要求的内建角色。例如:

​ In order to connect to a mongod that enforces authorization with the --auth option, you must use the --username and --password options, and the connecting user must have the serverStatus and top privileges.

​ The most appropriate built-in role that has these privileges is clusterMonitor.

3、授权角色规则

db.grantRolesToUser('cool', [{
    role: 'mongotopRole',
    db: 'admin'
    }]
)

4、使用mongotop命令

至此,权限配置已经完成,可正常使用命令,不过需要附加一些参数,例如:

mongotop -u username -p password --authenticationDatabase=admin

mongtop配置完成,mongostat同样按以上操作,具体权限可直接到官方文档进行搜索得知。

posted @ 2018-07-07 17:09  linjf  阅读(417)  评论(0编辑  收藏  举报