1、下载安装
cat <<EOF> /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=0
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
EOF
yum install -y mongodb-org
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、权限配置
#先创建管理员账户
mongo --port 27017 -u "adminUser" -p "asd123456" --authenticationDatabase "admin"
db.system.users.find();
db.changeUserPassword("adminUser","asd123456")
第一步:创建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