MongoDB学习05:用户及安全

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/damage_e/article/details/78945713

安全

  • 开启
    1. auth开启
      在mongod.conf中加入auth = true
      查找mongod服务:ps -ef|grep mongod|grep 12345
      停止mongod服务:kill pid
      创建用户:createUser({user:"<name>",pwd:" ",customData:{"用户说明"},roles:[{role:"<role>",db:"<database>"}]})
      1.角色类型:read,readWrite,dbAdmin,dbOwner,userAdmin
      createUser({user:"testAdmin",pwd:"mongotest",customData:{"testAdmin"},roles:[{role:"userAdmin",db:"admin"},{role:"read",db:"test"}]})
      2.集群角色(clusterAdmin,clusterManager…)
      3.备份角色(backup,restore…)
      4.其他特殊权限(DBAdminAnyDatabase…)
      创建角色:creatRole()
      { _id: "myAPP.appUser,role:"appUser",db:"myApp",
      privileges:[
      {resource :{db:"myApp",collection:" "},actions:["find","createCollection","dbStats","collStats"]}
      {resource :{db:"myApp",collection:"logs"},actions:["insert"]}
      {resource :{db:"myApp",collection:"data"},actions:["insert","update","remove","compact"]}
      {resource :{db:"myApp",collection:"system.indexes"},actions:["find"]}
      {resource :{db:"myApp",collection:"system.namespaces"},actions:["find"]}
      ],roles:[]}
    2. keyfile开启

猜你喜欢

转载自blog.csdn.net/damage_e/article/details/78945713