Saturday, February 19, 2022

[SOLVED] Error changing default dbPath for MongoDB on CentOS 7

Issue

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


Solution

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.



Answered By - Dheeraj vats
Answer Checked By - Clifford M. (WPSolving Volunteer)