Moving MongoDB dbpath to an AWS EBS device
I’m using CentOS 7 via AWS.
I’d like to store MongoDB data on an attached EBS instead of the default /var/lib path.
However, when I edit
/etc/mongod.conf to point to a new dbpath, I’m getting a permission denied error.
Permissions are set correctly to mongod.mongod on the dir.
One Solution collect form web for “Moving MongoDB dbpath to an AWS EBS device”
TL;DR – The issue is SELinux, which affects what daemons can access. Run
setenforce 0 to temporarily disable.
You’re using a flavour of Linux that uses SELinux.
SELinux can potentially control which activities a system allows each
user, process and daemon, with very precise specifications. However,
it is mostly used to confine daemons like database
engines or web servers that have more clearly defined data access and
activity rights. This limits potential harm from a confined daemon
that becomes compromised. Ordinary user-processes often run in the
unconfined domain, not restricted by SELinux but still restricted by
the classic Linux access rights
To fix temporarily:
sudo setenforce 0
This should disable SELinux policies and allow the service to run.
To fix permanently:
/etc/sysconfig/selinux and set this:
The service should now start-up fine.
The data dir will also work with Docker, i.e. something like:
docker run --name db -v /mnt/path-to-mounted-ebs:/data/db -p 27017:27017 mongo:latest
Warning: Both solutions DISABLE the security that SELinux provides, which will weaken your overall security. A better solution is to understand how SELinux works, and create a policy on your new data dir that works with mongod. See https://wiki.centos.org/HowTos/SELinux for a more complete tutorial.