0
votes

I have a mongoDB 3.0 on Amazon Ec2 server 。 I have already mounted a EBS volumes at /data for mongodb, and already changed /etc/mongod.conf dbpath to /data 。 I wanna know what is the correct permissions for "/data" is it should be set in sudo chown mongod:mongod /data or chown root:root /data and ps. by the way i'm using sudo mongod --config /etc/mongod.conf command to start mongo 。 and the last question is what should i set the chmod for /data is it 775 or 644 ?

1

1 Answers

1
votes

your mongo top-level directory and all data files need to be owned by the 'mongo' user, as you mentioned, since that's the owner of the mongo process when it runs. if the data files are owned by root, then user 'mongo' wouldn't be able to write to the files unless you made the files group writable, which is slightly more complicated. my mongo instance runs with all files (and the top level directory, /var/lib/mongo) owned by the mongo user, as i show below:

[ec2-user@ip-10-0-1-1 mongo]$ cd /var/lib/mongo
[ec2-user@ip-10-0-1-1 mongo]$ ls -ld .
drwxr-xr-x 5 mongod mongod 4096 Mar 23  2016 .
[ec2-user@ip-10-0-1-1 mongo]$ ls -l
total 81944
drwxr-xr-x 2 mongod mongod     4096 Mar 29  2015 journal
-rw------- 1 mongod mongod 67108864 Mar 29  2015 local.0
-rw------- 1 mongod mongod 16777216 Mar 29  2015 local.ns
drwx------ 2 root   root      16384 Jul 18  2014 lost+found
drwxr-xr-x 4 mongod mongod     4096 Nov  9 19:53 mongod1
[ec2-user@ip-10-0-1-1 mongo]$

regarding directory permissions, directories always need to be executable by whatever user is trying to change directories into it, so 755 permissions are more appropriate. if i were you, i'd change perms for your /data directory like this:

chown -R mongo:mongo /data
chmod 755 /data

hope this helps.