mongodb基本配置
创建超级管理员
- 进行使用命令进入mongo,命令行输入mongo
- use admin
- 创建超级管理员
db.createUser(
... {
... user: "用户名",
... pwd: "密码",
... roles: [ { role: "root", db: "admin" } ]
... }
... )
启用验证模式
-
打开
/lib/systemd/system/mongodb.service
-
添加 --auth参数
ExecStart=/usr/bin/mongod –auth
-
重新加载systemd服务
systemctl daemon-reload
-
重新启动MongoDB并连接创建的用户
service mongodb restart
-
mongo -u root -p 密码 --authenticationDatabase admin
开启远程连接
-
修改配置文件
-
vim etc/mongodb.conf
-
将bind_ip =127.0.0.1更改为bind_ip = 0.0.0.0
-
重启mongodb服务
service mongodb restart