Unable to create/open lock file: /data/mongod.lock errno:13 Permission denied

Unable to create/open lock file: /data/mongod.lock errno:13 Permission denied

Asked on December 31, 2018 in MongoDB.
Add Comment


  • 3 Answer(s)

    For the path of MongoDB in /etc/mongodb.conf was set to /var/lib/mongodb (primary install location and working). When I changed to /data/db (EBS volume) I was getting ‘errno:13 Permission denied’

    1.  ran sudo service mongodb stop.
    2. And then I used ls -la to see what group & owner mongodb assigned to /var/lib/mongodb (existing path) and I changed the /data/db (new path) with chown and chgrp to match. (example: sudo chown -R mongodb:mongodb /data/db)
    3. And then I updated the path in etc/mongodb.conf to /data/db and deleted the old mongo files in /var/lib/mongodb directory.
    4. Then I execute sudo service mongodb start and waited about a minute. If you try to connect to 27017 immediately you won’t be able to.
    5. And then  check /data/db (EBS volume) and mongo should have placed a journal, mongod.lock, local.ns, local.0, etc. If not try sudo service mongodb restart and check a minute later.

    Finally I spent over a hour with this. Changing the group and deleting the old files is probably not necessary, but that’s what worked for me.

    Answered on December 31, 2018.
    Add Comment

    For this (AWS EC2 instance, Ubuntu) helped:

    $ sudo mkdir -p /data/db/
    $ sudo chown `USERNAME` /data/db
    

    then verything worked good.

    Answered on December 31, 2018.
    Add Comment

    To allow to access to your /data/db folder.

    For that type sudo chown -R <USERNAME> /data/db, reinstate <USERNAME> by your username.

    To finding your username by typing whoami

    Answered on December 31, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.