1

I changed /etc/mongod.conf's dbpath to /mgodb and then I execute the follow command:

  1. mkdir /mgodb
  2. chown mongod:mongod /mgodb
  3. chmod 0755 /mgodb

Then I run service mongod start, and get errors like:

initAndListen: 20 Attempted to create a lock file on a read-only directory: /mgodb

I tried to change /usr/lib/systemd/system/mongod.service's User and Group to root, it also get the same error.

But I cat run mongod --fork --config /etc/mongod.conf through command line.

1
  • Step 2. should probably be chown -R mongod:mongod /mgodb. -R being a recursive change to the folder and all sub-folders.
    – John K. N.
    Sep 19, 2017 at 6:54

1 Answer 1

2

If you look that /etc/mongod.conf, what are values of processManagement.pidFilePath and storage.dbPath? It sounds like that system tries to create files to some subdirectory, what don't exists or is not owned by user what is used to start mongod process.

You should never start your mongod with root user. And if you have done that, f.ex. when starting mongod to maintenance mode, always remember to chown -R user: <dir> data files back to the right owner.

1
  • thanks, chcon -Rv --type=mongod_var_lib_t /mgodbb command resolved my problem. but i'm not fimilar with this command. i'll find more document about this.
    – sydnash
    Sep 19, 2017 at 3:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.