【问题标题】:How to run Mongodb as a service with authentication on a windows machine如何在 Windows 机器上通过身份验证将 Mongodb 作为服务运行
【发布时间】:2020-08-31 16:49:16
【问题描述】:

备注:我用的是win10。 我的目标是当 Windows 将 mongodb 作为具有身份验证的服务启动时(您无法在没有身份验证的情况下进入数据库)但我无法在 Windows 机器上执行此操作(在 linux 中它可以工作) 我在这里写下我尝试过的步骤:

  1. 下载 MongoDB

  2. 将 conf 从默认更改为以下

# mongod.conf
  http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: C:\MongoDB\Server\4.0\data
  journal:
    enabled: true

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path:  C:\MongoDB\Server\4.0\log\mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1

security:
    authorization: enabled
setParameter:
   enableLocalhostAuthBypass: false

  1. 在 Admin 集合中创建一个 Admin 用户。

db.createUser( { 用户:“....”, 密码:“...”, 角色: [ {角色:“根”,数据库:“管理员”} ] } )

  1. 使它成为一项服务:
sc.exe create MongoDB 
binPath=“\”C:\MongoDB\Server\4.0\bin\mongod.exe\” 
–service
config=\”C:\MongoDB\Server\4.0\bin\mongod.cfg\”” DisplayName= “MongoDB” start= “auto”

获得反馈成功。 但是当我重新启动计算机时,mongod 没有启动,如果我不指定mongod --auth,我仍然可以在没有身份验证的情况下进入 如何通过身份验证将 Mongod 作为服务运行?我究竟做错了什么? 当我尝试手动激活服务时,出现以下错误 Error photo

【问题讨论】:

  • 您可以在任务计划程序中创建一个任务,并将您的批处理文件作为 Windows 服务
  • 是的,使用任务调度程序是一个选项,但我更喜欢避免它,并使用身份验证作为服务运行它

标签: windows mongodb


【解决方案1】:

安全标签的问题。当我想在 Windows 10 中启动服务时,我遇到了同样的问题。我从 Windows 服务属性复制命令,然后在命令提示符下运行。

提示显示错误:

无法识别的类别:安全

我找到了解决方案,它是正确编写带有选项的安全标签。

我猜 YAML 需要一些特定的输入。这是解决方案。

security:
    authorization: enabled

【讨论】:

  • 标签对我不起作用。我在开头使用了双空格,在中间使用了空格。 MongDB V4.2
【解决方案2】:

我遇到了同样的问题。

在您的 mongodb.cfg 中,使用 2 个空格(而不是 TAB)来缩进 authorization: enabled

【讨论】:

  • 2 个空格不是强制性的。单个空格或 4 个空格都可以。 TAB 是问题所在。
猜你喜欢
  • 2020-03-16
  • 2017-03-03
  • 1970-01-01
  • 2014-02-14
  • 2016-04-24
  • 1970-01-01
  • 2011-07-31
  • 2017-01-15
  • 1970-01-01
相关资源
最近更新 更多