ITPub博客

首页 > IT职业 > IT图书 > MongoDB:Read and write access to da

MongoDB:Read and write access to da

IT图书 作者:nanquanc 时间:2021-09-09 10:21:30 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.


图片描述

image.png

刚创建数据库没有权限的问题(就是当前状态不安全),解决方法:

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 runsprocessManagement:
  timeZoneInfo: /usr/share/zoneinfo

security:
  authorization: enabled   //添加权限设置

5.重启服务

service mongod  restart
  1. 重新连接

mongo  或者  mongo  -u  admin  -p admin123# 端口可以带可以不带

ok

图片描述

image.png



作者:呼呼哥
链接:https://www.jianshu.com/p/f55da2d80414


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1556/viewspace-2820935/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    109
  • 访问量
    854