- 创建文件:
vi /etc/yum.repos.d/mongodb-org-5.0.repo
- 增加配置文件:
[mongodb-org-5.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/5.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc
- 安装:
sudo yum install -y mongodb-org
- 启动:
systemctl start mongod.service
- 连接:
mongo 127.0.0.1:27017
- 创建数据库:
use 数据库名称
- 添加用户:
db.createUser({ user:"name", pwd:"pwd", roles:["readWrite", "dbAdmin"] })
- 修改配置文件:
vi /etc/mongod.conf
security:
authorization: "enabled"
- 重启:
systemctl restart mongod.service
- 连接:
mongo 127.0.0.1:27017
- 进入数据库:
use 数据库名称
- 测试认证是否开启:
db.auth("name", "pwd")
- 返回1则成功
- 完成!