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
来源: http://www.bubuko.com/infodetail-2862652.html