1.配置MongoDB的yum源
# vi /etc/yum.repos.d/mongodb-org-4.0.repo
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
# yum makecache
2.安装MongDB
yum -y install mongdb-org
3.查看安装路径 whereis mongod
查看修改配置文件 vi /etc/mongod.conf
启动 systemctl start mongod.service
停止 systemctl stop mongod.serv
查看状态 status mongod.service
4.外网访问需要关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
5.启动Mongo Shell
命令 mongo
查看数据库 show dbs
6.设置mongodb远程访问
编辑mongod.conf注释bindIp,并重启mongodb.(这句配置代表只能本机使用,所以需注释)
vi /etc/mongod.conf
重启mongodb 使其生效
systemctl restart mongod.service