4

I am trying to run multiple mongod instances on the same centos machine with different config files.

I am getting following error while running the instance as a service:

sudo service mongod1 start

/var/lib/mongo1: boost::filesystem::status: Permission denied: "/var/lib/mongo1/mongod.lock"

I have added the permissions for the /var/lib/mongo1 using:

sudo chmod -R 600 /var/lib/mongo1

I also tried with 700, 755 and 777 at the end but nothing seems to work.

mongod:mongod is the owner of the folder /var/lib/mongo1

Any help is appreciated.

prcoder
  • 154
  • 1
  • 14
  • When you say different configuration files, do you mean `mongod.conf` or do you mean different `systemd` service scripts? –  Feb 19 '18 at 19:50
  • I am using different mongod.conf and systemd scripts as well. Basically, this is an attempt to run a replica set on system boot. – prcoder Feb 21 '18 at 09:54
  • Moved on to using Docker for running local MongoDB Replica Set. This issue is no more relevant for me. Didn't try the solutions mentioned here as I had no time to move on to the other solutions. Thanks for the help anyway! – prcoder Mar 20 '20 at 05:08

4 Answers4

2

I know this is really late but I was struggling with this for days and just now found the fix. That being said for future users running into this issue the solution if you're using SELinux is to check the context of the default mongodb path against your own to make sure they are the same by executing

ls -dZ /var/lib/mongo/

the output should look something like this

drwxr-xr-x. mongod mongod system_u:object_r:mongod_var_lib_t:s0 /var/lib/mongo/

if it's not then you can copy it by doing

chcon -R --reference=/var/lib/mongo /your/path

the source can be found here

0

Maybe the lock file is missing? Which might explain why chmod isn't having the desired effect...

Try:

 touch /var/mongo1/mongod.lock 
 chown mongod:mongod
 chmod 600 /var/mongo1/mongod.lock 
0

important :

Don't try to restart mongo using sudo as it tries to change the user to root where as /var/lib/mongodb owner is mongod:mongod

Gru
  • 67
  • 1
  • 7
-1

Please remember that Directories needs to have execute permission, but the files within the directories do not need to execute permission.

The following 2 commands worked for me

$ sudo chmod -R 770 /var/lib/mongo1
$ sudo find /var/lib/mongo1 -type f -exec chmod 660 {} \;   

This will first give everything under /var/lib/mongo1 execute permission, and then return all the normal files to having only read and write, but not execute.

Muhammad Tariq
  • 3,318
  • 5
  • 38
  • 42