1. 程式人生 > >MongoDB學習05:使用者及安全

MongoDB學習05:使用者及安全

安全

  • 開啟
    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開啟