標籤:mongod ram html 開啟 tab 文檔查看 enc red com
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同樣按以上操作,具體許可權可直接到官方文檔進行搜尋得知。
mongodb授權使用mongotop