建立/etc/yum.repos.d/mongodb-org-4.0.repo
檔案,編輯內容如下:
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
執行以下命令安裝最新版的mongodb:
sudo yum install -y mongodb-org
配置mongod.conf
允許遠端連線:
$ vim /etc/mongod.conf
# Listen to all ip address
bind_ip = 0.0.0.0
啟動mongodb:
sudo service mongod start
建立管理員使用者:
$ mongo
>use admin
db.createUser(
{
user: "myUserAdmin",
pwd: "abc123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
}
)
啟用許可權管理:
$ vim /etc/mongod.conf
#security
security:
authorization: enabled
重啟mongodb:
sudo service mongod restart
大功告成!