選擇 CentOS 最小安裝後
# yum -y install epel-release bind-utils net-tools sysstat
# yum -y update
# systemctl disable firewalld
# vi /etc/selinux/config
SELINUX=disabled
# reboot
以上是我習慣裝完OS 後的習慣,僅參考用
接下來才是真的安裝 MongoDB 4.2
編輯 /etc/yum.repos.d/mongodb.repo
# vi /etc/yum.repos.d/mongodb.repo
[MongoDB]
name=MongoDB Repository
baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
透過 yum 安裝
# yum -y install mongodb-org
手動啟動服務
# systemctl start mongod.service
設定下次重開機後自動啟用
# systemctl enable mongod.service
檢查安裝的版本
# mongod --version
db version v4.2.1
git version: edf6d45851c0b9ee15548f0f847df141764a317e
OpenSSL version: OpenSSL 1.1.1 FIPS 11 Sep 2018
allocator: tcmalloc
modules: none
build environment:
distmod: rhel80
distarch: x86_64
target_arch: x86_64
測試可否進入 mongo shell
# mongo
安裝好的 MmongoDB ,預設只允許 localhost 可以登入
如果確認你的網路環境夠安全的話,請修改 /etc/mongod.conf
# vi /etc/mongod.conf
bindIp: 127.0.0.1 ---> 0.0.0.0
存檔,重新啟動 mongod
# systemctl restart mongod.service
預設 port 為 tcp 27017
# netstat -na | grep LISTEN
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN