6

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

Brandon
  • 1,447
  • 2
  • 21
  • 41
  • so what's the question exactly? `service` command does not have `--logpath` parameter. Log rotation is a feature. – Alex Blex Mar 16 '18 at 15:50
  • Is the answer not in the log: Error parsing YAML config file? What is on line 20, col. 4? – chris Mar 16 '18 at 15:57
  • To confirm, is the yaml file the mongod.conf file? Otherwise, I do not know where to find `yaml-cpp` or any other similar file is? – Brandon Mar 16 '18 at 15:59
  • @AlexBlex I more explicitly stated the questions at the top of the post – Brandon Mar 16 '18 at 16:02
  • Now it makes even less sense. The status clearly shows it is malformed config, not log. Check what config is used in the service. – Alex Blex Mar 16 '18 at 16:08
  • 1
    Remove extra space before `wiredTiger` in line 20. [YAML](https://en.wikipedia.org/wiki/YAML) is indent-sensitive. – Alex Blex Mar 16 '18 at 16:18
  • @AlexBlex I added what I assume is the yaml file. Line 20 is wiredTiger which makes no sense. Also, there are 2 questions because there are 2 ways to run mongod. Through the cli through `mongod --option --option --etc` where you can specify the log. `service mongod start/stop/etc` is the other arguably better way because it is uses the config file. So my goal is to either solve the `--logpath` issue so that I can run it one way, or the other way so that I can use the config file. – Brandon Mar 16 '18 at 16:19
  • I removed the line and that error disappeared, so thanks! However, after restarting, the rest of the errors remained. – Brandon Mar 16 '18 at 16:22
  • @Brandon, I asked to **remove** the space, not to **add** the one. Please read the docs https://docs.mongodb.com/manual/reference/configuration-options/index.html and correct your config file. Don't try to guess and randomly delete or add something. Learn what the server expects from you. It is very well documented. Otherwise it won't work. – Alex Blex Mar 16 '18 at 16:42
  • @AlexBlex I don't believe that I added a space, I deleted a trailing one originally. After reading another discussion, I ended up commenting out wiredTiger and instead set `engine: wiredTiger` which lead to me to a `Failed Global Initialization` issue which related back to the earlier log issue. – Brandon Mar 16 '18 at 17:05

2 Answers2

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

Hopefully, that's will do!

Dr.jacky
  • 3,341
  • 6
  • 53
  • 91
Debotos Das
  • 519
  • 1
  • 6
  • 17
1
sudo systemctl enable mongod
sudo systemctl restart mongod
sudo journalctl -u mongod.service

Hopefully, that will do!

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

Hendy Irawan
  • 20,498
  • 11
  • 103
  • 114