MongoDB can not start by the command `service mongod start`

According to @Markus W Mahlberg, and after run these command, the problem has been solved. [sudo] chown mongodb.mongodb -R /var/lib/mongodb


If you ran the command mongod as root on the server while testing your configuration file, as in:

$ mongod -f /etc/mongod.conf

The mongo server will generate the mongo.lock file and the WiredTiger.lock files and further files in the mongodb folder with root:root ownership as in:

-rw-------  1 mongodb mongodb      36864 Nov 25 12:03 index-95--8062076833940689665.wt
-rw-------  1 mongodb mongodb      45056 Nov 25 12:03 index-96--8062076833940689665.wt
-rw-------  1 mongodb mongodb      36864 Nov 25 12:03 index-99--8062076833940689665.wt
drwx------  2 mongodb mongodb       4096 Nov 25 15:23 journal/
-rw-------  1 mongodb mongodb      45056 Nov 25 15:32 _mdb_catalog.wt
-rw-------  1 root    root             0 Nov 25 15:32 mongod.lock
-rw-------  1 mongodb mongodb      36864 Nov 25 15:32 sizeStorer.wt
-rw-------  1 mongodb mongodb        114 Oct 17 17:41 storage.bson
-rw-------  1 mongodb mongodb         44 Oct 17 17:41 WiredTiger
-rw-------  1 mongodb mongodb       4096 Nov 25 15:32 WiredTigerLAS.wt
-rw-------  1 root    root            21 Nov 25 15:22 WiredTiger.lock
-rw-------  1 mongodb mongodb       1201 Nov 25 15:32 WiredTiger.turtle
-rw-------  1 mongodb mongodb     188416 Nov 25 15:32 WiredTiger.wt

The service is most likely configured to run mongod with the mongodb user. which will not have permission to remove, or overwrite the WiredTiger.lock nor the mongod.lock or any other file that were created when mongod was running using the root user. In the case above the /var/lib/mongodb/WiredTiger.turtle

The solution is to reset the ownership of all the files in the folder in the case above the /var/lib/mongodb/ folder to the mongodb user:

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

That should solve the issue.

Tags:

Mongodb