• 首页
  • 栏目
  • ERP
  • mongo报错:not authorized on bb to execute command { create: \“xxx\“...}

mongo报错:not authorized on bb to execute command { create: \“xxx\“...}

  • 2021-09-01
  • Admin

mongo报错:

{
        "ok" : 0,
        "errmsg" : "not authorized on bb to execute command { create: \"a\", capped: \"1\", lsid: { id: UUID(\"f01a76ec-6261-4886-9a3f-e07169eed122\") }, $db: \"bb\" }",
        "code" : 13,
        "codeName" : "Unauthorized"
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

以下是使用docker容器创建mongo的正确步骤:

Mongo 启动docker容器,设置用户权限:

默认情况下,mongo数据库没有添加认证约束,为了增强数据库的安全性,我们需要对数据库添加授权认证

注意:在运行mongo容器命令中添加--auth参数

docker run --name mongo-master -p 27017:27017 -v /etc/localtime:/etc/localtime:ro -v /home/mongo/db:/data/db -d mongo:4.4.8 --auth
  • 1

命令说明:

  • -name:自定义别名
  • -p 27017:27017 : 将容器的27017 端口映射到主机的27017 端口
  • -v /etc/localtime:/etc/localtime:ro:挂载系统时区
  • -d /home/mongo/db:/data/db : 将主机中 /home/mongo/db 挂载到容器的 /data/db,作为mongo数据存储目录
  • –antu:开启密码授权访问
mongo;
  • 1
use admin;
  • 1
db.createUser({
  user : 'root',
  pwd : '123456',
  roles : [
    'clusterAdmin',
    'dbAdminAnyDatabase',
    'userAdminAnyDatabase',
    'readWriteAnyDatabase'
  ]
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

原文:https://blog.csdn.net/w_monster/article/details/120034383

联系站长

QQ:769220720