就让我
她不在这里,她无处追寻,可她在我心里 -- 挥之不去
mongodb 权限管理,添加用户授权

非权限下启动 mongo

/usr/local/mongodb3.4.4/bin/mongod -f /usr/local/mongodb3.4.4/conf/10000.conf
/usr/local/mongodb3.4.4/bin/mongo --port 10000

切换到 mongo admin 库添加管理员,默认 (db)admin (collection)users 第一个用户为超级管理员

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

重启 mongo

kill -HUP {mongo pid}

注意添加( -auth )

/usr/local/mongodb3.4.4/bin/mongod -f /usr/local/mongodb3.4.4/conf/10000.conf -auth
/usr/local/mongodb3.4.4/bin/mongo --port 10000

管理员账号必须到 admin 库中去授权

use admin
db.auth('admin','admin')

添加一个数据指定数据库的管理员

use ecommerce
db.createUser({user:"cleey",pwd:"cleey",roles:["dbOwner"]})
db.auth('cleey','cleey')

或者admin 下

db.createUser({user:"cleey",pwd:"cleey",roles:[{role:"dbOwner",db:"ecommerce"}]})

admin 库下查看所有用户

需要 admin 授权 auth 可查看

> use admin
switched to db admin
> db.system.users.find()
{ "_id" : "admin.admin", "user" : "admin", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "367uQBl3wZGHM8AjIv75ew==", "storedKey" : "yU1V9nPK7xv01mNmI9I/oibmuxM=", "serverKey" : "fa5WKibh9XQYTkwMyxpFcUtJOq4=" } }, "roles" : [ { "role" : "root", "db" : "admin" } ] }
{ "_id" : "ecommerce.cleey", "user" : "cleey", "db" : "ecommerce", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "uAI0N9hvg6Ct4CCSE6AaWQ==", "storedKey" : "gpZQ3vVbzP/+foK/Lh3/jrtYxDs=", "serverKey" : "WN89bM5oL140TQNkRHyrXQBdg1g=" } }, "roles" : [ { "role" : "dbOwner", "db" : "ecommerce" } ] }
<< 上一篇 vagrant 在本地编辑 js 和 css 后,vagrant nginx或 apache 读取的数据为乱码 redis cluster 搭建 下一篇 >>
文章标签
随意 | Created At 2014 By William Clinton | 蜀ICP备14002619号-4 |