创建yum源
vi /etc/yum.repos.d/mongodb-org-3.6.repo
[mongodb-org-3.6]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc
yum install mongodb-org
启动mongodb
systemctl start mongod
设置管理员及密码
mongo
use admin
db.createUser({ user: "root", pwd: "你的密码", roles: [{ role: "root", db: "admin" }] })
exit
启用密码验证
vi /etc/mongod.conf
security:
authorization: enabled
重启mongod
systemctl restart mongod
登录mongo命令行
mongo
use admin
db.auth('root','你的密码')
查看所有用户
use admin
db.system.users.find()
删除用户
use admin
db.dropUser('用户名')
创建数据库、创建用户
use dbName
db.createUser({ user: "dbUser", pwd: "密码", roles: [{ role: "dbOwner", db: "dbName" }] })
文章作者:DOTATONG
发布日期:2018-05-04
评论