安装
参见:http://www.jianshu.com/p/48f2274ddef0
配置用户权限
创建超级管理员
# mongo --host=127.0.0.1 --port=27017 > use admin > db.createUser( { user:"admin", pwd:"password", roles:[{role:"root", db:"admin"}] } )
修改配置文件
# vim /data/mongodb/conf/mongodb.yml security: authorization: enabled
重启
# systemctl restart mongodb.service
创建普通用户:对mydb库有读写权限
> use mydb > db.createUser( { user:"myuser", pwd:"123456", roles: [{role:"readWrite", db:"mydb"}] } )
创建只读用户:对所有库有读权限
> use admin > db.createUser( { user:"readonly", pwd:"123456", roles: [{role:"readAnyDatabase", db:"admin"}] } )