启动mongodb 4.0 报错
rpm 安装好之后,修改了一番配置参数,结果报错如下:
Error parsing YAML config file yaml-cpp error at line
9月 11 17:26:05 pc-2 mongod[17302]: Error parsing YAML config file: yaml-cpp: error at line
9月 11 17:26:05 pc-2 mongod[17302]: try '/usr/bin/mongod --help' for more information
思来想去就修改了一个参数,允许远程登录的bindIp…
bindIp:0.0.0.0
一番摸索,原来是冒号之后要留一空格…很坑
改完之后,果断启动成功
修改如下:
bindIp: 0.0.0.0 //冒号之后要留空格
systemctl restart mongod
[root@pc-2 network-scripts]# netstat -anpt | grep 27017
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 17375/mongod
上面这些错误,都是因为配置文件格式的错误,很无语
mongodb 3.0之后配置文件采用YAML格式,这种格式非常简单,使用:表示,开头使用“空格”作为缩进。需要注意的是,“:”之后有value的话,需要紧跟一个空格,如果key只是表示层级,则无需在“:”后增加空格(比如:systemLog:后面既不需要空格)。按照层级,每行4个空格缩进,第二级则8个空格,依次轮推,顶层则不需要空格缩进。如果格式不正确,将会出现上面的错误
仔细读完这段文字就会找到解决办法
下面附上我的正确配置文件供参考
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
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
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp: