MongoDB:Read and write access to
2018-07-06 本文已影响0人
呼呼哥
部署环境: Ubuntu 16.04.1 LTS (GNU/Linux 4.13.0-36-generic x86_64)
WARNING: Access control is not enabled for the database.Read and write access to data and configuration is unrestricted.

刚创建数据库没有权限的问题(就是当前状态不安全),解决方法:
1.在控制台输入命名(前提/ data/db 路径存在)
mongod --port 27017 --dbpath /data/db
2.重启服务器连接实例
mongo --port 27017
3.创建管理员
use admin
db.createUser(
{
user: "admin", //用户名
pwd: "admin123", //密码
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] //权限
}
)
4.退出, 修改权限
vi /etc/mongod.conf
修改如下:
net:
#port: 27017
bindIp: 0.0.0.0 //用于远程服务器的连接
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
security:
authorization: enabled //添加权限设置
5.重启服务
service mongod restart
- 重新连接
mongo 或者 mongo -u admin -p admin123
# 端口可以带可以不带
ok

如果添加用户有权限的问题参考此文章:
errmsg" : "not authorized on admin to execute command { listCollections: 1.0, filter: {}, $db: "admin" }",
如果不懂或者有什么错误,欢迎下方评论