3

I needed more space on my mongo database so I went to my local computer shop, bought a new hard drive, installed it. Then I copied all the files from /var/lib/mongodb to /media/didier/mongodb/mongodb/ and changed the ownership of /media/didier/mongodb/mongodb/ with the command sudo chown -R mongodb:mongodb /media/didier/mongodb/mongodb/. Then, I changed the config file at /etc/mongod.conf to point to the good data directory. Basically, I followed the instruction at Changing MongoDB data store directory.

The permissions looks good, the config file looks fine too, but when I start mongodb using sudo service mongod start I have the following exception in my logs

014-07-16T09:11:37.362-0400 [initandlisten] MongoDB starting : pid=5899 port=27017 
dbpath=/media/didier/mongodb/mongodb/ 64-bit host=miaou
2014-07-16T09:11:37.362-0400 [initandlisten] db version v2.6.3
2014-07-16T09:11:37.362-0400 [initandlisten] git version: 255f67a66f9603c59380b2a389e386910bbb52cb
2014-07-16T09:11:37.362-0400 [initandlisten] build info: Linux build12.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-07-16T09:11:37.362-0400 [initandlisten] allocator: tcmalloc
2014-07-16T09:11:37.362-0400 [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1" }, storage: { dbPath: "/media/didier/mongodb/mongodb/" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2014-07-16T09:11:37.362-0400 [initandlisten] exception in initAndListen std::exception: boost::filesystem::status: Permission denied: "/media/didier/mongodb/mongodb/", terminating
2014-07-16T09:11:37.362-0400 [initandlisten] dbexit: 
2014-07-16T09:11:37.362-0400 [initandlisten] shutdown: going to close listening sockets...
2014-07-16T09:11:37.362-0400 [initandlisten] shutdown: going to flush diaglog...
2014-07-16T09:11:37.362-0400 [initandlisten] shutdown: going to close sockets...
2014-07-16T09:11:37.362-0400 [initandlisten] shutdown: waiting for fs preallocator...
2014-07-16T09:11:37.362-0400 [initandlisten] shutdown: lock for final commit...
2014-07-16T09:11:37.362-0400 [initandlisten] shutdown: final commit...
2014-07-16T09:11:37.362-0400 [initandlisten] shutdown: closing all files...
2014-07-16T09:11:37.362-0400 [initandlisten] closeAllFiles() finished
2014-07-16T09:11:37.362-0400 [initandlisten] dbexit: really exiting now

Any idea what goes wrong? When I simply run sudo mongod --config /etc/mongod.conf everything works fine. So I suppose it is a permission problem.

cheers!

Community
  • 1
  • 1
user983716
  • 1,992
  • 1
  • 22
  • 32
  • Did you install mongod using an `rpm` or `deb` package? – Pete Garafano Jul 16 '14 at 13:50
  • I followed the instructions. It uses deb. http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/ – user983716 Jul 16 '14 at 14:03
  • 1
    even a damned `chmod -R 777` did not help! – user983716 Jul 16 '14 at 14:45
  • Did you `sudo chown mongod:mongod /media/didier/mongodb/mongodb/`? – Pete Garafano Jul 16 '14 at 14:51
  • the mongod user and group do not exist. But the mongodb does but it changes nothing. Do you know if I can see what happen under the hood of service mongod start (with debug or verbatim mode)? – user983716 Jul 16 '14 at 15:13
  • There isn't much magic "under the hood" aside from `mongod` trying to open the files in the `dbpath` with r/w access. You definitely don't want to chmod 777; you should set the ownership to match the user your `mongod` service is running as. Given you need to provide more information to troubleshoot this problem, you might want to post on the [mongodb-user forum](https://groups.google.com/forum/#!forum/mongodb-user) for more back & forth discussion. FYI, with the 2.6 Ubuntu installer, the expected ownership on your `dbpath` should be `mongodb:mongodb` (which it looks like you've already tried) – Stennie Jul 16 '14 at 22:45
  • A gist/pastebin link with an `ls -laR /media/didier/mongodb/mongodb/` would help clarify the current permissions. It also seems odd to have `mongodb/mongodb` in the path; is that correct or should there just be a single `mongodb` directory? – Stennie Jul 16 '14 at 22:46

2 Answers2

3

The problem is that the hard drive is not accessible to the mongodb user. To share a hard drive between all users, you need to change the /etc/fstab by adding the following line:

UUID=a43bc179-f0e5-464b-bd77-1be6a7581ec2   /media/mongodb ext4  defaults  0   0

That will mount the hard drive to the /media/mongodb directory at boot time. See https://help.ubuntu.com/community/Fstab for more information.


In short, to use a different hard drive as data location on mongodb on a ubuntu machine one needs to do the following three steps:

  1. make sure the mongodb user can access the new hard drive (fstab)
  2. make sure the user mongodb has access to the data directory (chown)
  3. change the mongo config file (/etc/mongod.conf)
Captain Whippet
  • 2,143
  • 4
  • 25
  • 34
user983716
  • 1,992
  • 1
  • 22
  • 32
1

I think the issue is you need to change permissions of your /media mount point to have r+x (read and execute) for 'other' groups and users; at least that fixed it for me. Doing

sudo chmod a+rx /media

will do it. You want to make sure this is also true for the whole path to the mongodb data I think, so you could do sudo chmod -R a+rx /media to make it recursive, or change the permissions for the drive, then each subfolder up to the mongodb folder:

sudo chmod a+rx /media/didier
sudo chmod a+rx /media/didier/mongodb
sudo chmod a+rx /media/didier/mongodb/mongodb
wordsforthewise
  • 13,746
  • 5
  • 87
  • 117