1.配置MongoDB的yum源
执行:
tee /etc/yum.repos.d/mongodb-org-4.0.repo <<-'EOF'
[mngodb-org]
name=MongoDB Repository
baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/4.0/x86_64/
gpgcheck=0
enabled=1
EOF
更新:
yum update
2.安装MongoDB
安装:
yum -y install mongodb-org
配置文件:
vim /etc/mongod.conf
net:
port: 27017
bindIp: 0.0.0.0
3.启动
systemctl start mongod.service
systemctl stop mongod.service
systemctl status mongod.service
systemctl enable mongod.service #开机启动
启动错误日志位置:
/var/log/mongodb/mongod.log
4.外网访问:
关闭防火墙
systemctl stop firewalld.service
systemctl stop iptables
5. 用户名密码登录
--创建用户
连接数据库:
mongo
use admin
db.createUser({user:'admin',pwd:'123456',roles:[{role:'root',db:'admin'}]})
打开密码认证
vim /etc/mongod.conf
security:
authorization: enabled
6. 测试连接