mongoDB权限管理

开启mongoDB的权限管理,找了很多文章,最后发现都不行。比如这个网址,当然也可能是我操作不对...

按照文中操作后报错:

auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.

打开mongod.log有这样的报错:

SASL SCRAM-SHA-1 authentication failed for igguser on admin from client 169.254.93.138:58172 ; UserNotFound: Could not find user "myuser" for db "admin"

 于是,admin 库中执行:

 db.createUser(
     {
       user:"user",
       pwd:"123456",
       roles:[{role:"userAdminAnyDatabase",db:"admin"}]
     }
  )

最后运行程序,成功!!!

综上,在admin中共执行了两个操作

 db.createUser(
     {
       user:"root",
       pwd:"123456",
       roles:[{role:"userAdminAnyDatabase",db:"admin"}]
     }
  )
  
  db.createUser(
     {
       user:"user",
       pwd:"123456",
       roles:[{role:"readWriteAnyDatabase",db:"admin"}]
     }
  )

如果要配置mongo集群,则按照如下配置

mongoDB权限管理_第1张图片

 最后运行 rs.initiate() 即可

你可能感兴趣的:(服务器开发,mongodb,数据库,database)