MongoDB: exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating

前端 未结 14 1702
轻奢々
轻奢々 2020-12-02 04:37

I created /data/db in root directory and ran ./mongod:

[initandlisten] exception in initAndListen: 20 Attempted to create a lock fi         


        
相关标签:
14条回答
  • 2020-12-02 05:08

    Check if SElinux is enabled. If it is in enforcing mode just try with permissive mode. In case that helps you should create SElinux policies for mongodb.

    You can try with audit2allow - check https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/security-enhanced_linux/sect-security-enhanced_linux-fixing_problems-allowing_access_audit2allow

    0 讨论(0)
  • 2020-12-02 05:11

    I dealt with the same problem:

    Change to the MongoDB directory which contains the bin directory, and run:

    sudo bin/mongod 
    

    Running MongoDB as the root user you might be asked to enter the root password. If you still can not run the MongoDB, then check the permissions for MongoDB's data directory. Enter:

    ls -ld /data
    

    or type ls -l / for the permissions for all directories and files in the directory including the /data directory.

    The permission mode for the root user should be "rwx", meaning the root user is able to read, write and execute the files. To make this happen, we use:

    chmod 755 /data 
    

    755 is a octal notation to set the permissions, of the /data directory to "rwxr-xr-x", which means the root user can read, write and execute, whereas the "group" and "everyone"are able to only read and execute.

    Note: When you can't do this, type instead:

    sudo chmod 755 /data   
    

    to set the permission as the root user.

    Then, when done with that step, recapture the permission modes using:

    ls -ld /data
    

    which should look like:

    drwxr-xr-x  3 root  wheel  102 Mar  3 17:00 /data
    

    You don't need to worry about the "d" at the beginning, and notice that the permissions reflect "rwxr-xr-x".

    You can now change back to the MongoDB directory and type:

    sudo bin/mongod  
    

    to run MongoDB.

    0 讨论(0)
  • 2020-12-02 05:12

    If your system is using SELinux, make sure that you use the right context for the directory you created:

    ls -dZ /data/db/
    ls -dZ /var/lib/mongo/
    

    and clone the context with:

    chcon -R --reference=/var/lib/mongo /data/db
    
    0 讨论(0)
  • 2020-12-02 05:13

    you just need to run the command as a super user:

    just type from the terminal: sudo su mongod

    0 讨论(0)
  • 2020-12-02 05:14

    Fix the permissions of /data/db (or /var/lib/mongodb):

    sudo chown -R mongodb: /data/db
    

    then restart MongoDB e.g. using

    sudo systemctl restart mongod
    

    In case that does not help, check your error message if you are using a data directory different to /var/lib/mongodb. In that case run

    sudo chown -R mongodb: <insert your data directory here>
    

    source

    0 讨论(0)
  • 2020-12-02 05:14

    Nice solutions, but I wonder why nobody is giving the solution for windows.

    If you are using windows you just have to "Run as Administrator" the cmd.

    0 讨论(0)
提交回复
热议问题