參考 MongoDB 官方網站:https://docs.mongodb.com/manual/tutorial/install-mongodb-enterprise-on-red-hat/
1.配置 yum 源
- 創建yum源文件
touch /etc/yum.repos.d/mongodb-enterprise.repo
- 修改配置文件
vim /etc/yum.repos.d/mongodb-enterprise.repo
[mongodb-enterprise]
name=MongoDB Enterprise Repository
baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/4.0/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
2.使用 yum 安裝MongoDB
yum install -y mongodb-enterprise
3.配置SELinux
- 安裝semanage命令
yum -y install policycoreutils-python
- 如果SELinux處於
enforcing
模式,則啟用對MongoDB部署將使用的相關端口的訪問(例如27017
)
semanage port -a -t mongod_port_t -p tcp 27017
- 將
SELINUX配置文件
設置為disabled 模式,禁用SELinux
vim /etc/selinux/config
SELINUX=disabled
- 將SELinux配置文件設置為
permissive 模式,解除限制
vim /etc/selinux/config
SELINUX=permissive
- 修改完配置文件后,需要重啟使設置生效
reboot
4.MongoDB的使用
- 啟用/停止/重啟 MongoDB 服務
systemctl start mongod.service
systemctl stop mongod.service
ssystemctl restart mongod.service
- 使MongoDB伴隨系統啟動
systemctl enable mongod.service
- 在本機使用MongoDB
mongo
- 退出MongoDB
exit
- 遠程連接MongoDB
首先修改MongoDB的監聽地址,將配置文件內把 bind_ip=127.0.0.1 這一行注釋掉或者是修改成 bind_ip=0.0.0.0
vim /etc/mongodb.conf
確保MongoDB的程序啟動時,使用以下命令連接使用
mongo IP:PORT