1、下载安装
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/RPMS/mongodb-org-server-4.0.4-1.el7.x86_64.rpm
rpm -Uvh mongodb-org-server-4.0.4-1.el7.x86_64.rpm
2、基础配置
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
net:
port: 27017
bindIp: 0.0.0.0
3、权限配置
第一步:创建test数据库
use test
第二步:在test用户中新建test用户
db.createUser({ user: "test", pwd: "testPwd", roles: [{ role: "dbOwner", db: "test" }] })
第三步:修改MongoDB安装目录中的配置文件 /etc/mongod.conf
将#security:的注释去掉,然后添加authorization: enabled #注意authorization前面要有两个空格
security:
authorization: enabled
第四步:重启MongoDB服务
service mongod restart
第五步:测试
mongo 127.0.0.1:27017/test -u test -p testPwd
原文地址:https://www.cnblogs.com/rongkang/p/10024891.html