chartgpt生成的,记录备份一下
- 第一步编辑/etc/yum.repos.d/mongodb-org-6.0.repo文件
bash
[mongodb-org-6.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/6.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc
- 更新yum数据库
bash
sudo yum update -y
- 安装mongodb
bash
sudo yum install -y mongodb-org
- 启动服务
bash
sudo systemctl start mongod
- 设置 MongoDB 服务开机自启动:
bash
sudo systemctl enable mongod
- 检查 MongoDB 服务状态:
bash
sudo systemctl status mongod
- 添加用户
7.1 添加管理员用户
bash
mongo
use admin
db.createUser({
user: "adminUser",
pwd: "password123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
})
7.2 添加普通用户
bash
use test
db.createUser({
user: "yourUser",
pwd: "password123",
roles: [ { role: "readWrite", db: "yourDatabase" } ]
})
# 然后就可以执行
mongo -u yourUser -p password123 --authenticationDatabase test