0

How do we change the options like dbPath, path etc in mongod.conf file. I am using centos 7. Every time i change the default dbPath and try to restart mongod service it fails.(It works fine with default config options like ->

storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log
)

I have tried changing permissions to new directory using chown mongod:mongod /path/to/data and chmod 0755 /path/to/data

Every time i get error (in mongod.log file )-> 2017-03-27T06:03:27.182+0000 I STORAGE [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /path/to/data, terminating

Dheeraj vats
  • 348
  • 5
  • 17
  • has nothing to do with azure and\or development, probably better off on serverfault – 4c74356b41 Mar 25 '17 at 11:28
  • Probably even better to post on the Unix stack exchange site ([link](https://unix.stackexchange.com)). Also, when you post there, probably a good thing to include details of the permissions on the various directories you're targeting, and actually showing the modifications to your `mongod.conf` – David Makogon Mar 25 '17 at 14:06
  • According to the error, it seems a permission issue. Do you check upper folder permissions? All of the path should be `755`. You could use the command to check `ls -ld /` `ls -ld /path` `ls -ld /path/to` `ls -ld /path/ti/data` – Shui shengbao Mar 27 '17 at 05:49
  • Hi, do you solve this issue? – Shui shengbao Mar 27 '17 at 07:08
  • Not Yet, Same issue. BTW I just updated the error (exact copy paste from the log file) – Dheeraj vats Mar 27 '17 at 07:30
  • This seems to be the issue with centos only, things seems to be working fine with ubuntu. – Dheeraj vats Mar 27 '17 at 07:31
  • Could you access the data file by using mongod user? `su - mongod` – Shui shengbao Mar 27 '17 at 07:42
  • @Dheerajvats Do you check this [question](http://stackoverflow.com/questions/15229412/unable-to-create-open-lock-file-data-mongod-lock-errno13-permission-denied)? – Shui shengbao Mar 27 '17 at 07:45

1 Answers1

1

I had to configure the /etc/sysconfig/selinux file. Change SELINUX=enforcing to SELINUX=disabled to allow MongoDB to start on CentOS. You must reboot the system for the changes to take effect.

Dheeraj vats
  • 348
  • 5
  • 17