我正在使用在CentOS 7的AWS EC2实例上使用mongoDB 3.6.3。
有两个问题(仅需回答一个):
- 为什么手动通过cli执行
sudo mongod --storageEngine etc
命令时,--logpath
会阻止mongod命令呢? sudo service mongod status
为什么显示故障信息呢?
当我运行以下命令时(因为当前sudo service mongod start
不起作用,但是下面的命令可以工作),如果我指定--logpath
,则它会失败,但是如果没有指定,则可以正常运行。不幸的是,如果我不指定,所有日志都会出现在绝对错误的位置/
。
sudo mongod --storageEngine wiredTiger --dbpath /data --bind_ip 127.0.0.1,apiIP --logpath /var/log/mongodb/mongod.log --auth --fork
以下是当我尝试按原样运行上述命令时发生的情况:
I CONTROL [main] log file "/var/log/mongodb/mongod.log" exists; moved to "/var/log/mongodb/mongod.log.2018-03-16T15-16-01".
据我所知,它与当前已存在的文件发生冲突。
仅供参考,sudo service mongod status
返回:
mongod.service - mongodb database
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2018-03-16 15:11:53 UTC; 9min ago
Process: 26620 ExecStart=/usr/bin/mongod $OPTIONS run (code=exited, status=2)
Main PID: 26620 (code=exited, status=2)
Mar 16 15:11:53 ip-* systemd[1]: Started mongodb database.
Mar 16 15:11:53 ip-* systemd[1]: Starting mongodb database...
Mar 16 15:11:53 ip-* mongod[26620]: F CONTROL [main] Failed global initialization: FileNotOpen: Failed to open "/var/log/mongodb/mongod.log"
Mar 16 15:11:53 ip-* systemd[1]: mongod.service: main process exited, code=exited, status=1/FAILURE
Mar 16 15:11:53 ip-* systemd[1]: Unit mongod.service entered failed state.
Mar 16 15:11:53 ip-* systemd[1]: mongod.service failed.
/etc/mongod.conf
# 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: /data
# logpath: /log/mongod.log
journal:
enabled: true
engine: wiredTiger
# 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: 127.0.0.1, apiIP
感谢@AlexBlex注意到yaml文件中的间距问题。
有了这个解决,状态错误就出现了这行代码:
Unrecognized option: storage.wiredTiger
wiredTiger
前的多余空格。YAML 是缩进敏感的。 - Alex Blex