mongodb 3.2 集群认证及创建用户


认证之前先创建用户

mongodb 创建用户


db.createUser({user:"lixiaomeng",pwd:"11111",roles:[{role:"root",db:"admin"}]})
db.createUser({user:"dbapp",pwd:"dbapp",roles:[{role:"dbAdminAnyDatabase",db:"admin"}]})

 

创建认证文件

openssl rand -base64 753 >mongodb-keyfile

将文件复制到所有副本集机器中


使用--keyFile参数指定前面生成的keyfile文件,如下

keyFile = /data0/mongodb/mongodb-keyfile

重启三台机器全部mongod进程 


mongodb 创建用户


db.createUser({user:"lixiaomeng",pwd:"11111",roles:[{role:"root",db:"admin"}]})


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




mongo --host 127.0.0.1 --authenticationDatabase admin -u lixiaomeng -p

 


db.auth("lixiaomeng","isolxm123");


mongodb 创建用户


db.createUser({user:"lixiaomeng",pwd:"11111",roles:[{role:"root",db:"admin"}]})
db.createUser({user:"dbapp",pwd:"dbapp",roles:[{role:"dbAdminAnyDatabase",db:"admin"}]})

你可能感兴趣的:(mongo)