MongoDB service doesn't start. errno:13 Permission denied

16,618

Solution 1

We must make all the directories/files owned by mongod user. For this:

sudo chown -R mongodb:mongodb /data/db

Solution 2

I found a special case where the use of symlinks appears to fail:

Using a standard enterprise install of mongodb except I changed the /var/lib/mongodb to a symlink as I wanted to use an XFS filesystem for my database folder and a third filesystem for the log folder.

$sudo systemctl start mongod (fails with a message no permission to write to mongodb.log).. but it succceded if I started with the same configuration file:

.. as the owner of the external drives (ziggy) I was able to start $mongod --config /etc/mongodb.conf --fork

I eventually discovered that .. the symlinks pointed to a different filesystem and the mongodb (user) did not have permission to browse the folder that the symlink referred. Both the symlinks and the folders the symlinks referred had expansive rights to the mongod user so it made no sense?

Share:
16,618
cespon
Author by

cespon

Updated on June 04, 2022

Comments

  • cespon
    cespon almost 2 years

    I have installed MongoDB on a Ubuntu server like is indicated in the docs http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/. Then, I have modified the configuration file /etc/mongod.conf for, later, run a mongod service.

    MongoDB runs correctly if I execute:

    sudo mongod -f /etc/mongod.conf
    

    But MongoDB stops if I execute:

    sudo service mongod start
    

    In the config file /etc/mongod.conf I changed only this:

    dbpath=/data/db
    logpath=/root/logs/mongod.log
    port=20000
    

    With this configuration, the log file is not created too.

    If I don't modify the previous values indicated, the service starts correctly. The default values are:

    dbpath=/var/lib/mongodb
    logpath=/var/log/mongodb/mongod.log
    port = 27017
    

    Because the log file is not created with the custom configuration, I have only changed the dbpath for see the error:

    [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?
    

    I tried to run the following commands but without success:

    sudo chown -R `id -u` /data/db
    
    sudo rm /var/lib/mongodb/mongod.lock
    mongod --repair
    

    Stack:

    • Ubuntu 14.10
    • MongoDB 2.6.5