编辑mongo.conf后,MongoDB状态失败(代码退出,状态=2)

3
我正在尝试使用Robo 3T远程连接我的Google Cloud服务器,连接到MongoDB v4.0.11,以便我可以从Windows中查看数据。
我正在运行Ubuntu 18.04LTS Minimal。为了启用对MongoDB的远程连接,我首先在我的管理数据库中创建了一个管理员和根用户。
我的问题是,一旦我在/etc/mongod.conf中的security:中添加authorization: "enabled"并重新启动MongoDB,当我运行$:systemctl status mongod时,我会得到以下状态。
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2019-08-06 16:43:51 BST; 1min 20s ago
     Docs: https://docs.mongodb.org/manual
  Process: 6517 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=2)
 Main PID: 6517 (code=exited, status=2)

Aug 06 16:43:51 instance-1 systemd[1]: Started MongoDB Database Server.
Aug 06 16:43:51 instance-1 mongod[6517]: Unrecognized option: processManagement.authorization
Aug 06 16:43:51 instance-1 mongod[6517]: try '/usr/bin/mongod --help' for more information
Aug 06 16:43:51 instance-1 systemd[1]: mongod.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Aug 06 16:43:51 instance-1 systemd[1]: mongod.service: Failed with result 'exit-code'.

/etc/mongod.conf的示例

# mongod.conf
# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log
# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1

# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

#security:
  authorization: "enabled"
#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

看起来在/etc/mongod.conf中存在无效参数,但从我在网上阅读的内容来看,我看不出问题所在。

3个回答

12

错误的:

#security:
  authorization: "enabled"

正确:

security:
  authorization: enabled

8

针对4.x版本,似乎您需要修改已列出的现有安全性部分

#security:
  authorization: "enabled"

将其替换为security.authorization: enabled

security:
      authorization: "enabled"

您应该可以重新加载并测试认证是否按预期工作。

如果您深入文档,您将找到相关部分在这里

security.authorization

Type: string

Default: disabled

Enable or disable Role-Based Access Control (RBAC) to govern each user’s access to database resources and operations.

Set this option to one of the following:
Value     Description
enabled   A user can access only the database resources and actions for which they have been granted privileges.
disabled  A user can access any database and perform any action.

您可以在sudo nano /etc/mongod.conf更改安全设置。 - DragonFire
1
对于版本4及以上,它是security.authorization:已启用。 - DragonFire

3
在我的情况下,问题在于我使用制表符缩进了authorization: enabled这一行。当我使用两个空格代替制表符后,它正常工作。

谢谢。那正是我的问题所在。 - sklimkovitch
我也遇到了同样的问题。我为我的选项卡浪费了一个小时。 - Данияр

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接