简体   繁体   中英

Mongodb /var/log/mongodb/mongod.log prevents mongod from starting

I am using mongodb 3.6.3 on a centos 7 aws ec2 instance.

2 Questions (only one needs to be answered):

  1. Why is the --logpath preventing the mongod command if done manually through the cli with sudo mongod --storageEngine etc
  2. Why is sudo service mongod status showing the failure that it is?

When I run the below command, (since currently, sudo service mongod start isn't working but the below works) it fails when I specify the --logpath but will run without it. Unfortunately, when I run it without it, all of my logs end up in the / which is absolutely the wrong location.

sudo mongod --storageEngine wiredTiger --dbpath /data --bind_ip 127.0.0.1,apiIP --logpath /var/log/mongodb/mongod.log --auth --fork

Below is what happens when I try to run that above line as is.

I CONTROL [main] log file "/var/log/mongodb/mongod.log" exists; moved to "/var/log/mongodb/mongod.log.2018-03-16T15-16-01".

From what I can tell, it is conflicting with the currently existent

Just for reference, sudo service mongod status returns:

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

Thanks to @AlexBlex for noticing the spacing issue in the yaml file.

With that sorted, the status error has this line Unrecognized option: storage.wiredTiger

  1. cd /var/log
  2. sudo mkdir -m 777 mongodb
  3. sudo service mongod start
  4. sudo service mongod status

希望,这会做!

sudo systemctl enable mongod
sudo systemctl restart mongod
sudo journalctl -u mongod.service

Hopefully, that will do!

Reference: https://stackoverflow.com/a/51286526/122441

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM