2

I'm using MongoDB 3.6.2 on openSUSE Tumbleweed. Today when I tried to open the mongo shell there was a connection error. When I checked the status of mongodb.service by using

sudo systemctl status mongodb

it showed

Active: failed

without too much useful information. Then I checked

sudo mongod --repair

I found the following error:

STORAGE  [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating

So I went to check my /etc/mongodb.conf file and the storage part looks like the follows:

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine: mmapv1
#  mmapv1:
#  wiredTiger: true

and the network part looks like this:

net:
  port: 27017
  bindIp: 127.0.0.1,::1
  ipv6: true

Other parts of this file unlikely caused this error so I omitted them.

I don't think I have ipv6 turned on on my machine but this shouldn't cause the error either because I tried to set

ipv6: false

it still did not work.

The problem is, I normally make mongodb as a service and enable it to start automatically at boot by

sudo systemctl start mongodb
sudo systemctl enable mongodb

And this worked fine until today. However, when I manually run

sudo mongod --dbpath /var/lib/mongodb --port 27017

it works correctly. So seems like mongodb still does not recognize the new dbpath /var/lib/mongodb. I did run

sudo mongod --config /etc/mongodb.conf

but looks like this did not help.

Please advise. Do I have to manually specify --dbpath every time? Can I continue to run mongodb as a service using the .conf file?

Thanks in advance.

rollschild
  • 105
  • 1
  • 12
  • Check your running processes `ps -ef | grep mongod`. Does that actually show `mongod --config /etc/mongodb.conf` or something else? You probably should also check the log. The default configuration probably puts that in `/var/log/mongodb/mongod.log` unless you changed something else. – Neil Lunn Apr 19 '18 at 00:23
  • BTW `sudo mongod --repair` failed because you did not use `--dbpath`, but you likely don't need to repair if you started an instance successfully with `--dbpath` directly. – Neil Lunn Apr 19 '18 at 00:24

1 Answers1

0

SOLVED:

It turned out that the ipv6 settings actually matters. I changed the /etc/mongodb.conf file to:

# What type of connections to allow.
net:
  port: 27017
  bindIp: 127.0.0.1
  ipv6: false

then

sudo mongod --config /etc/mongodb.conf

After I did this I tried to start the service again but got the same error. I went to check the log located at /var/log/mongodb/mongod.log and found the following error:

2018-04-18T21:02:36.561-0400 E STORAGE  [initandlisten] WiredTiger error (13) [1524099756:561216][4061:0x7f107fa1b9c0], file:WiredTiger.wt, connection: /var/lib/mongodb/WiredTiger.turtle: handle-open: open: Permission denied
2018-04-18T21:02:36.561-0400 E -        [initandlisten] Assertion: 28595:13: Permission denied src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 413
2018-04-18T21:02:36.562-0400 I STORAGE  [initandlisten] exception in initAndListen: Location28595: 13: Permission denied, terminating

So I did this:

sudo chown -R mongodb:mongodb /var/lib/mongodb/

Then I started the service using

sudo systemctl start mongodb

and it started correctly!

So the solution is:

  1. Remove the ,::1 from

    net:
      port: 27017
      bindIp: 127.0.0.1,::1
      ipv6: false
    

and make sure ipv6: false since ipv6 is disabled on my machine.

  1. Make sure you have the right permission for your data path, in my case it's /var/lib/mongodb.

Thanks.

rollschild
  • 105
  • 1
  • 12