1、先从官网下载安装包官网下载地址
2.本地解压并创建目录
2.1创建data和log目录
2.2创建mongodb.cfg
# mongod.conf# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/# Where and how to store data.
storage:dbPath: D:\图灵架构师\分布式专题\mongodb\mongodb5.0.27\datajournal:enabled: true
# engine:
# mmapv1:
# wiredTiger:# where to write logging data.
systemLog:destination: filelogAppend: truepath: D:\图灵架构师\分布式专题\mongodb\mongodb5.0.27\log\mongod.log# network interfaces
net:port: 27017#bindIp: 127.0.0.1#bindIp: 172.16.0.11bindIp: 0.0.0.0#processManagement:#security:#authorization: enabled#operationProfiling:#replication:#sharding:## Enterprise-Only Options:#auditLog:#snmp:
3.配置环境变量
4.mongodb的bin目录下cmd里运行命令
mongod --config D:\图灵架构师\分布式专题\mongodb\mongodb5.0.27\mongod.cfg
4.1第一次要注释掉配置文件里
4.2连接mongod
mongo --port 27017 --host ip
4.3创建管理员用户和库
use admin
db.createUser({user:"root",pwd:"root",roles:[{role:"userAdminAnyDatabase",db:"admin"
}]
})验证登录下:db.auth("root","root")
可以创建其他库和用户;
use test
db.createUser({user:"test",pwd:"test",roles:[{role:"readWrite",db:"admin"
}]
})
4.4打开配置里的认证
4.5重启mongodb然后就可以用密码连接了