1.创建admin 用户
#mongo
#use admin
#db.createUser({user:"admin",pwd:"123456",roles:[{role:"root",db:"admin"}]})
2.配置授权访问
#vim /etc/mongo.conf
增加:auth=true
3.创建库/用户
#mongo
#use admin
#db.auth("admin", "123456")
#use vcollege
#db.createUser({user:"vcollege",pwd:"123456",roles:[{role:"readWrite",db:"vcollege"}]})
4.登录验证
mongo --host 127.0.0.1 -u 'vcollege' --authenticationDatabase 'vcollege' -p'123456'mongo --host 127.0.0.1 -u 'vcollege' --authenticationDatabase 'vcollege' -p'123456'