Install MongoDB Community Edition on Red Hat or CentOS — MongoDB Manual
按照官方指南进行安装
/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
yum install -y mongodb-org
默认数据位置
/var/lib/mongo
默认日志位置
/var/log/mongodb
配置文件位置
/etc/mongod.conf
修改
将net:bindIp: 127.0.0.1 改为 0.0.0.0
1.SElinux
semanage port -a -t mongod_port_t -p tcp 27017
2.防火墙
firewall-cmd --zone=public --add-port=27017/tcp --permanent firewall-cmd --reload
service mongod start #或者 systemctl start mongod
关闭 service mongod stop 或者 systemctl stop mongod
重启 service mongod restart 或者 systemctl restart mongod
chkconfig mongod on #或者 systemctl ennable mongod
mongo --host 127.0.0.1:27017
sudo service mongod stop
sudo yum erase $(rpm -qa | grep mongodb-org)
sudo rm -r /var/log/mongodb sudo rm -r /var/lib/mongo