我在centos 7 aws ec2实例上使用mongodb 3.6.3。
2个问题(只需要回答一个问题):
sudo mongod --storageEngine etc
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
答案 0 :(得分:0)
cd /var/log
sudo mkdir -m 777 mongodb
sudo service mongod start
sudo service mongod status
希望如此!
答案 1 :(得分:0)
sudo systemctl enable mongod
sudo systemctl restart mongod
sudo journalctl -u mongod.service
希望如此!