We will see how to change the default MongoDB database server directory, by default, it is stored all data in /var/lib/mongo. Now we will see how to change this directory.
Before making any changes, stop MongoDB service
Create a new directory where we need to move the storage location for Mongo
Edit the configuration file /etc/mongod.conf and modify the following fields accordingly:
Make sure the new directory has mongod user access.
Now we need the SELinux Configuration if it is enforced.
Configure SELinux, if it’s in enforcing mode.
Since we have changed the default folder of the MongoDB, SELinux Policy does not allow MongoDB process to access /sys/fs/cgroup if running SELinux in enforcing mode.
Make sure we have the package check policy installed
Create a custom policy file mongodb_cgroup_memory.te
Now Compile and load the custom policy module.
Once created, compile and load the custom policy module by running these three commands:
- Data directory
- Log File Directory
- pid file directory
Log File Directory
PID file directory
Now add the following for firewall and iptables.
Once all these changes are done, Start mongo daemon and MongoDB service.
Now MongoDB will start using new directory (/data/techrunnr/mongo) as default data directory.
© 2019, Techrunnr. All rights reserved.