安装mongoDB
powershell
$ vim /etc/yum.repos.d/mongodb-org.repo
$ dnf install mongodb-org
$ systemctl enable mongod
$ systemctl status mongodmongodb-org.repo
[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配置mongoDB
权限控制
powershell
$ vim /etc/mongod.conf
$ systemctl restart mongodmongod.conf
security:
authorization: enabled用户创建
shell
$ mongosh
$ use adminshell
db.createUser(
{
user: "mongoAdmin",
pwd: "changeMe",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)shell
$ mongo -u mongoAdmin -p --authenticationDatabase admin
$ use admin
$ show users踩坑之路
无法再次启动
shell
Process: ***ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)这个问题主要是因为权限不足
shell
chown -R mongod:mongod /var/lib/mongo
chown -R mongod:mongod /var/log/mongo
chown -R mongod:mongod /tmp/*.sock