changing mongod dbpath raise permission error - mongodb

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!

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:
make sure the mongodb user can access the new hard drive (fstab)
make sure the user mongodb has access to the data directory (chown)
change the mongo config file (/etc/mongod.conf)

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

Related

mongod src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp no file

I've really been all over StackOverflow on this and couldn't find a solution. I have uninstalled Homebrew and Mongo via, well, brew. Nothing seems to fix it. Any help would be much appreciated.
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] MongoDB starting : pid=7684 port=27017 dbpath=/data/db 64-bit host=Matts-MacBook-Pro.local
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] db version v3.4.6
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2l 25 May 2017
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] allocator: system
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] modules: none
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] build environment:
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] distarch: x86_64
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] target_arch: x86_64
2017-08-03T20:29:40.017-0400 I CONTROL [initandlisten] options: {}
2017-08-03T20:29:40.018-0400 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-08-03T20:29:40.019-0400 E STORAGE [initandlisten] WiredTiger error (2) [1501806580:19955][7684:0x7fffbdc783c0], file:WiredTiger.wt, connection: /data/db/WiredTiger.wt: handle-open: open: No such file or directory
2017-08-03T20:29:40.029-0400 I - [initandlisten] Assertion: 28595:2: No such file or directory src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 269
2017-08-03T20:29:40.029-0400 I STORAGE [initandlisten] exception in initAndListen: 28595 2: No such file or directory, terminating
2017-08-03T20:29:40.029-0400 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-08-03T20:29:40.029-0400 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2017-08-03T20:29:40.029-0400 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-08-03T20:29:40.029-0400 I CONTROL [initandlisten] now exiting
2017-08-03T20:29:40.029-0400 I CONTROL [initandlisten] shutting down with code:100
I also have to spent more than 4 hours to find a solution you asked. In my case, the stack trace is same as in your case.
I used MongoDB 4.2. But I need to downgrade it to MongoDB 3.4. After downgrading to 3.4 above error can be seen. Then again I updated MongoDB to 4.2. Still there was that error.
Tried many solutions on Stack Overflow but nothing solved my issue. As my final option I run below command.
mongod --dbpath /data/db --repair
But it also did not work.
There were some files on my /data/db directory.
Those are WiredTiger, WiredTiger.lock, WiredTiger.turtle, diagnostic.data, journal and mongod.lock.
Removed all the files in /data/db directory.
rm -rf /data/db/*
Run above command with sudo if you are not the root user.
Then I run mongod --dbpath /data/db --repair command again.
Then I could start MongoDB successfully by running mongod --dbpath /data/db.
Do not forget add bin/mongod to PATH in .bash_profile(If you are using Mac).

Having trouble installing and using mongodb. on my macosx and a readonly /data/db

I want to install Mongodb for my next online web course but the thing is I'm having so much issues. I have been installing and uninstall mongodb so many times I think it's conflicting with temp ... Can someone guide me to the process please, really would appreciate it.
The error when running mongodb:
017-07-02T10:31:41.547-0400 I STORAGE [initandlisten] exception in
initAndListen: 20 Attempted to create a lock file on a read-only
directory: /data/db, terminating 2017-07-02T10:31:41.547-0400 I
NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-07-02T10:31:41.547-0400 I NETWORK [initandlisten] shutdown: going
to flush diaglog... 2017-07-02T10:31:41.547-0400 I CONTROL
[initandlisten] now exiting 2017-07-02T10:31:41.547-0400 I CONTROL
[initandlisten] shutting down with code:100 –
I tried installing it on homebrew , nothing happen, I tried installing it manually still having troubles.. I know my basic like cd,ls,rm,pwd,touch, when using the terminal, If theres process that i can wipe everything associate with mangodb in my Macbook and install it again i have no problem.
found out that /data/db is readonly
MongoDB is already installed but you have some issue launching it.
017-07-02T10:31:41.547-0400 I STORAGE [initandlisten] exception in
initAndListen: 20 Attempted to create a lock file on a read-only
directory: /data/db, terminating 2017-07-02T10:31:41.547-0400 I
NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-07-02T10:31:41.547-0400 I NETWORK [initandlisten] shutdown: going
to flush diaglog... 2017-07-02T10:31:41.547-0400 I CONTROL
[initandlisten] now exiting 2017-07-02T10:31:41.547-0400 I CONTROL
[initandlisten] shutting down with code:100 –
Change the permission of /data/db
sudo chown -R `id -un` /data/db
Now you should start the daemon without problem:mongod
then connect with your mongo client by typing. mongo
ok.. then got this. 2017-07-02T10:50:39.069-0400 I CONTROL
[initandlisten] options: { repair: true, storage: { dbPath: "/data/db"
} } 2017-07-02T10:50:39.069-0400 W - [initandlisten] Detected unclean
shutdown - /data/db/mongod.lock is not empty.
2017-07-02T10:50:39.069-0400 E NETWORK [initandlisten] Failed to
unlink socket file /tmp/mongodb-27017.sock Permission denied
2017-07-02T10:50:39.069-0400 I - [initandlisten] Fatal Assertion 28578
at src/mongo/util/net/listen.cpp 195 2017-07-02T10:50:39.070-0400 I -
[initandlisten] ***aborting after fassert() failure
your /tmp is maybe not readable, try:
chmod 1777 /tmp

mongodb server is not starting, mac os

When running:
mongod
I get:
2017-04-30T11:19:56.234+0600 I CONTROL [initandlisten] MongoDB starting : pid=1160 port=27017 dbpath=/data/db 64-bit host=Interstellar
2017-04-30T11:19:56.234+0600 I CONTROL [initandlisten] db version v3.4.4
2017-04-30T11:19:56.234+0600 I CONTROL [initandlisten] git version: 888390515874a9debd1b6c5d36559ca86b44babd
2017-04-30T11:19:56.234+0600 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2k 26 Jan 2017
2017-04-30T11:19:56.234+0600 I CONTROL [initandlisten] allocator: system
2017-04-30T11:19:56.234+0600 I CONTROL [initandlisten] modules: none
2017-04-30T11:19:56.234+0600 I CONTROL [initandlisten] build environment:
2017-04-30T11:19:56.235+0600 I CONTROL [initandlisten] distarch: x86_64
2017-04-30T11:19:56.235+0600 I CONTROL [initandlisten] target_arch: x86_64
2017-04-30T11:19:56.235+0600 I CONTROL [initandlisten] options: {}
2017-04-30T11:19:56.235+0600 I STORAGE [initandlisten] exception in
initAndListen: 29 Data directory /data/db not found., terminating
2017-04-30T11:19:56.235+0600 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-04-30T11:19:56.235+0600 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-04-30T11:19:56.235+0600 I CONTROL [initandlisten] now exiting
2017-04-30T11:19:56.235+0600 I CONTROL [initandlisten] shutting down with code:100
I'm having trouble with this, badly need help
The problem is that if you run "mongod" the default path is /usr/data. NEVERTHELESS macOS Catalina does not accept creating a writable folder there. So after long research, in both here, and reddit, I finally got my server (mongod as well as Mongo) up and running. Try the following these steps:
mkdir -p /System/Volumes/Data/data/db
sudo chown -Rv <your_user_name> /System/Volumes/Data/data/db
sudo mongod --dbpath /System/Volumes/Data/data/db
This may run mongod and start the server. Open another terminal tab, and type Mongo.
First step
brew services start mongodb/brew/mongodb-community#4.4
Second step
cd /Users
whoami
cd to your whoami directory
mkdir data
cd data
mkdir db
mongod --dbpath ~/data/db
Third step
mongo
The problem is that there is no /data/db directory. Please issue this command:
sudo mkdir -p /data/db
If you're not worried about opening up permissions too widely, but just want to ensure that mongodb has permissions to start, you can also issue these commands. They may fix any problems you have if the above command alone doesn't solve things.
cd /
sudo chmod -R 777 data

I try to run mongod server on ubuntu : exception in initAndListen: 29 Data directory /data/db not found., terminating

I try to run a mongod server and its giving a error comment it below :
i tried few comment kill port and lock file comments not it dosent work ..
2016-11-14T03:52:20.271+0530 I CONTROL [initandlisten] MongoDB starting : pid=2921 port=27017 dbpath=/data/db 64-bit host=codepanda
2016-11-14T03:52:20.271+0530 I CONTROL [initandlisten] db version v3.2.10
2016-11-14T03:52:20.271+0530 I CONTROL [initandlisten] git version: 79d9b3ab5ce20f51c272b4411202710a082d0317
2016-11-14T03:52:20.271+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2016-11-14T03:52:20.271+0530 I CONTROL [initandlisten] allocator: tcmalloc
2016-11-14T03:52:20.271+0530 I CONTROL [initandlisten] modules: none
2016-11-14T03:52:20.271+0530 I CONTROL [initandlisten] build environment:
2016-11-14T03:52:20.271+0530 I CONTROL [initandlisten] distmod: ubuntu1604
2016-11-14T03:52:20.271+0530 I CONTROL [initandlisten] distarch: x86_64
2016-11-14T03:52:20.271+0530 I CONTROL [initandlisten] target_arch: x86_64
2016-11-14T03:52:20.271+0530 I CONTROL [initandlisten] options: {}
2016-11-14T03:52:20.308+0530 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2016-11-14T03:52:20.308+0530 I CONTROL [initandlisten] dbexit: rc: 100
You need to create the directory:
mkdir -p /data/db
This is because the directory '/data/db' you created is writable only by super user but you are trying to run as normal user. So, the following command
sudo chown -R $USER /data/db
makes you super user.
Now, try running
mongod.
MongoDB requires a data directory to store all data. MongoDB’s default data directory path is the absolute path \data\db on the drive from which you start MongoDB. Create this folder by running the following command in a Command Prompt
md \data\db
More detailed information given here.
https://stackoverflow.com/a/46886272/6242317
For new arrivals, consider that your /etc/mongodb.conf file may be out of date. Did you copy it from a previous installation or modify it using outdated instructions?
For example, as of Mongo 4.2 the smallfiles option is no longer recognized and MongoDB will reject the conf file and resort to defaults ( i.e. /data/db ).
The configuration file documentation is here:
https://docs.mongodb.com/manual/reference/configuration-options/

MongoDB, change db path, not working

I upgraded from debian 6 to debian 8. After that I upgraded MongoDB from ~2.5 to 3.2.9. They seemed to have changed the db path since I could not see any of my databases. I upgraded the dbpath. Stil I can't see any of my databases.
seprst#SESTOWS011:/data/db$ ls
graddays graddays.0 graddays.ns journal local local.0 local.ns mongod.lock mypdb mypdb.0 mypdb.ns
seprst#SESTOWS011:/data/db$ sudo service mongod stop
seprst#SESTOWS011:/data/db$ mongod --dbpath /data/db
2016-08-17T12:02:26.468+0200 I CONTROL [initandlisten] MongoDB starting : pid=22283 port=27017 dbpath=/data/db 64-bit host=SESTOWS011
2016-08-17T12:02:26.468+0200 I CONTROL [initandlisten] db version v3.2.9
2016-08-17T12:02:26.468+0200 I CONTROL [initandlisten] git version: 22ec9e93b40c85fc7cae7d56e7d6a02fd811088c
2016-08-17T12:02:26.468+0200 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1t 3 May 2016
2016-08-17T12:02:26.469+0200 I CONTROL [initandlisten] allocator: tcmalloc
2016-08-17T12:02:26.469+0200 I CONTROL [initandlisten] modules: none
2016-08-17T12:02:26.469+0200 I CONTROL [initandlisten] build environment:
2016-08-17T12:02:26.469+0200 I CONTROL [initandlisten] distmod: debian71
2016-08-17T12:02:26.469+0200 I CONTROL [initandlisten] distarch: x86_64
2016-08-17T12:02:26.469+0200 I CONTROL [initandlisten] target_arch: x86_64
2016-08-17T12:02:26.469+0200 I CONTROL [initandlisten] options: { storage: { dbPath: "/data/db" } }
2016-08-17T12:02:26.513+0200 I - [initandlisten] Detected data files in /data/db created by the 'mmapv1' storage engine, so setting the ac tive storage engine to 'mmapv1'.
2016-08-17T12:02:26.530+0200 I JOURNAL [initandlisten] journal dir=/data/db/journal
2016-08-17T12:02:26.545+0200 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed
2016-08-17T12:02:26.590+0200 I JOURNAL [initandlisten] warning couldn't write to / rename file /data/db/journal/prealloc.0: couldn't open file / data/db/journal/prealloc.0 for writing errno:9 Bad file descriptor
2016-08-17T12:02:26.590+0200 I STORAGE [initandlisten] exception in initAndListen: 13516 couldn't open file /data/db/journal/j._0 for writing er rno:9 Bad file descriptor, terminating
2016-08-17T12:02:26.590+0200 I CONTROL [initandlisten] now exiting
2016-08-17T12:02:26.590+0200 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2016-08-17T12:02:26.590+0200 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2016-08-17T12:02:26.590+0200 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2016-08-17T12:02:26.590+0200 I NETWORK [initandlisten] shutdown: going to close sockets...
2016-08-17T12:02:26.591+0200 I STORAGE [initandlisten] shutdown: waiting for fs preallocator...
2016-08-17T12:02:26.591+0200 I STORAGE [initandlisten] shutdown: final commit...
2016-08-17T12:02:26.591+0200 I STORAGE [initandlisten] shutdown: closing all files...
2016-08-17T12:02:26.591+0200 I STORAGE [initandlisten] closeAllFiles() finished
2016-08-17T12:02:26.591+0200 I CONTROL [initandlisten] dbexit: rc: 100
seprst#SESTOWS011:/data/db$ sudo service mongod start
seprst#SESTOWS011:/data/db$ mongo
MongoDB shell version: 3.2.9
connecting to: test
Server has startup warnings:
2016-08-17T12:02:40.540+0200 I CONTROL [initandlisten]
2016-08-17T12:02:40.540+0200 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-08-17T12:02:40.540+0200 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-08-17T12:02:40.540+0200 I CONTROL [initandlisten]
> show dbs
local 0.000GB
>
Any suggestions?
there is formatting issue with comment so posting as answer
ps -xa | grep mongod
open config file cat /etc/mongod.conf
for me it's dbPath: /var/lib/mongodb
you can check your settings.
to make changes permanent at your own risk
sudo service mongod stop
sudo ln -s /data/db/ /var/lib/mongodb
sudo chown mongodb:mongodb /data/db/
sudo service mongod start
//test if mongodb user can access new location:
sudo -u mongodb -s cd /data/db/