解决Error parsing YAML config file: yaml-cpp: error at line 32, column 1: end of map not found

本文详细介绍了如何使用YAML格式的配置文件启动MongoDB,并针对常见的配置错误进行了说明。提供了正确的配置示例,包括日志记录、数据存储、进程管理和安全性设置等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mongodb使用配置文件启动

mongod --config /etc/mongod.conf

碰到的各种错误

Error parsing YAML config file: yaml-cpp: error at line 32, column 1: end of map not found

Error parsing command line: the required argument for option '--config' is missing

Unrecognized option: auth
try 'mongod --help' for more information

上面这些错误,都是因为配置文件格式的错误,很无语

mongodb 3.0之后配置文件采用YAML格式,这种格式非常简单,使用<key>:<value>表示,开头使用“空格”作为缩进。需要注意的是,“:”之后有value的话,需要紧跟一个空格,如果key只是表示层级,则无需在“:”后增加空格(比如:systemLog:后面既不需要空格)。按照层级,每行4个空格缩进,第二级则8个空格,依次轮推,顶层则不需要空格缩进。如果格式不正确,将会出现上面的错误

仔细读完这段文字就会找到解决办法

附我的配置文件:
 

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
 systemLog:
    destination: file
    logAppend: true
    path: /var/log/mongodb/mongod.log

# Where and how to store data.
 storage:
    dbPath: /var/lib/mongo
    journal:
        enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# how the process runs
 processManagement:
    fork: true  # fork and run in background
    pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile

# network interfaces
 net:
    port: 26178
    bindIp: 0.0.0.0  # Listen to local interface only, comment to listen on all interfaces.

 security:
    authorization: enabled

注意复制过去可能会有格式问题,注意自己解决

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

裸睡的雨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值