Reputation: 78422
How to I get mongo to use a mounted drive on ec2? I really do not understand. I attached a volume on ec2 formatted the drive as root and start as root and yet as root I cant access? I am running on ubuntu 12.04. No other mongo is running
I see that mongo made a 'db' dir in /data i.e. /data/db
cd /
ls -al
drwxr-xr-x 4 root root 4096 Mar 5 16:28 data
cd /data
ls -al
total 28
drwxr-xr-x 4 root root 4096 Mar 5 16:28 .
drwxr-xr-x 24 root root 4096 Mar 5 16:28 ..
drwxr-xr-x 2 root root 4096 Mar 5 16:28 db
drwx------ 2 root root 16384 Mar 5 16:20 lost+found
sudo mkfs.ext3 /dev/xvdh
sudo mkdir /data
sudo su - -c 'echo "/dev/xvdh %s auto noatime 0 0" | sudo tee -a /etc/fstab'
sudo mount /data
sudo service mongodb start
mongodb start/running, process 17169
sudo ps -ef | grep mongod
ubuntu 15763 15634 0 16:32 pts/2 00:00:00 tail -f mongodb.log
ubuntu 18049 15766 0 16:43 pts/3 00:00:00 grep --color=auto mongod
Tue Mar 5 16:33:15 [initandlisten] MongoDB starting : pid=15890 port=27017 dbpath=/data 64-bit host=aws-mongo-server-east-staging-20130305161917
Tue Mar 5 16:33:15 [initandlisten] db version v2.2.3, pdfile version 4.5
Tue Mar 5 16:33:15 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
Tue Mar 5 16:33:15 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Tue Mar 5 16:33:15 [initandlisten] options: { bind_ip: "10.157.60.27", config: "/etc/mongodb.conf", dbpath: "/data", logappend: "true", logpath: "/var/log/mongodb/mongodb.log", replSet: "heythat" }
Tue Mar 5 16:33:15 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Tue Mar 5 16:33:15 dbexit:
Tue Mar 5 16:33:15 [initandlisten] shutdown: going to close listening sockets...
Tue Mar 5 16:33:15 [initandlisten] shutdown: going to flush diaglog...
Tue Mar 5 16:33:15 [initandlisten] shutdown: going to close sockets...
Tue Mar 5 16:33:15 [initandlisten] shutdown: waiting for fs preallocator...
Tue Mar 5 16:33:15 [initandlisten] shutdown: lock for final commit...
Tue Mar 5 16:33:15 [initandlisten] shutdown: final commit...
Tue Mar 5 16:33:15 [initandlisten] shutdown: closing all files...
Tue Mar 5 16:33:15 [initandlisten] closeAllFiles() finished
Tue Mar 5 16:33:15 [initandlisten] shutdown: removing fs lock...
Tue Mar 5 16:33:15 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Tue Mar 5 16:33:15 dbexit: really exiting now
Below is if I restart when I remove a lock file....
Tue Mar 5 16:59:15 [initandlisten] MongoDB starting : pid=21091 port=27017 dbpath=/data 64-bit host=aws-mongo-server-east-staging-20130305161917
Tue Mar 5 16:59:15 [initandlisten] db version v2.2.3, pdfile version 4.5
Tue Mar 5 16:59:15 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
Tue Mar 5 16:59:15 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Tue Mar 5 16:59:15 [initandlisten] options: { bind_ip: "10.157.60.27", config: "/etc/mongodb.conf", dbpath: "/data", logappend: "true", logpath: "/var/log/mongodb/mongodb.log", replSet: "heythat" }
Tue Mar 5 16:59:15 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Tue Mar 5 16:59:15 dbexit:
Tue Mar 5 16:59:15 [initandlisten] shutdown: going to close listening sockets...
Tue Mar 5 16:59:15 [initandlisten] shutdown: going to flush diaglog...
Tue Mar 5 16:59:15 [initandlisten] shutdown: going to close sockets...
Tue Mar 5 16:59:15 [initandlisten] shutdown: waiting for fs preallocator...
Tue Mar 5 16:59:15 [initandlisten] shutdown: lock for final commit...
Tue Mar 5 16:59:15 [initandlisten] shutdown: final commit...
Tue Mar 5 16:59:15 [initandlisten] shutdown: closing all files...
Tue Mar 5 16:59:15 [initandlisten] closeAllFiles() finished
Tue Mar 5 16:59:15 [initandlisten] shutdown: removing fs lock...
Tue Mar 5 16:59:15 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Tue Mar 5 16:59:15 dbexit: really exiting now
Upvotes: 193
Views: 221022
Reputation: 349
I was trying to use the db folder under my username but the mongo was trying to run with mongodb user. I realized I have to give global read permission to my home dir and then mongo was able to read sub directories.
Example:
/home/xyz/path/to/db
was readable and writable to mongodb.
But /home/xyz
was not readable to mongodb. after doing
chmod 755 /home/xyz
the problem is solved.
Upvotes: 0
Reputation: 1068
Got a similar error, fixed with removing all records (in my case directory journals
, and file mongo.lock...
), after that check port with sudo lsof -i:27017
, if smth running on it kill <PID of the process>
, and try to run ./mongod
again
Upvotes: 0
Reputation: 595
I got the same issue when I ran mongod command after installing it on Windows10. I stopped the mongodb service and started it again. Working like a charm
Command to stop mongodb service (in windows): net stop mongodb
Command to start mongodb server: mongod --dbpath PATH_TO_DATA_FOLDER
Upvotes: 2
Reputation: 7162
In Centos Server
this works for me
chown -R mongod:mongod /var/lib/mongo
Upvotes: 0
Reputation: 171
If you literally want a one line equivalent to the commands in your original question, you could alias:
mongo --eval "db.getSiblingDB('admin').shutdownServer()"
https://stackoverflow.com/a/11777141/7160782
Upvotes: 0
Reputation: 13015
I use this method to solve the problem:
sudo chown -R mongodb:mongodb /data/db
Upvotes: 484
Reputation: 1727
For me on CentOS 6.x:
sudo chown -R mongodb:mongodb <db-path>
sudo service mongod restart
And I have set a custom db-path
in /etc/mongod.conf
.
Upvotes: 0
Reputation: 337
Every time you when you try to start mongod just type
sudo mongod
or if permanently want to fix this just try to give rwx premission to /data/db folder
chmod +rwx data/
Upvotes: -2
Reputation: 58
Fix: sudo mongod
I had the same problem, running mongod with sudo privileges fixed it.
Coming from a windows environment, I used just mongod
to start the daemon, well it looks like we need the superuser privileges to access /data/db.
You can also give non root users Read and Write permissions to that path. check answers above for a guide!
Upvotes: -2
Reputation: 300
You could try by these ways. 1st.
sudo chown -R mongod:mongod /data/db
but at some times,this is not useful. 2nd. if the above way is not useful,you can try to do this:
mkdir /data/db #as the database storage path
nohup mongod --dbpath /data/db &
or type:
mongod --dbpath /data/db
to get the output stream
Upvotes: 0
Reputation: 11
I had the same problem.
I solved it by changing selinux status to permissive with below command:
setenforce 0
Upvotes: 1
Reputation: 2300
I had similar issue, the actual reason was that there was mongod session running already from my previous attempt.
I ran
killall mongod
and everything else ran just as expected.
killall
command would send a TERM signal to all processes with a real UID. So this kills all the running instances of mongod so that you could start your own.
Upvotes: 11
Reputation: 126
As of today, I tried to get my way through the to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating, and tried all the answer posted above to solve this problem, hence nothing worked out by adding
sudo chown -R mongodb:mongodb /data/db
Unless I added my current user permission to the location path by
sudo chown $USER /data/db
Hope this helps someone. Also I just installed Mongo DB on my pi. Cheers!
Upvotes: 7
Reputation: 6605
My mongo (3.2.9) was installed on Ubuntu, and my log file had the following lines:
2016-09-28T11:32:07.821+0100 E STORAGE [initandlisten] WiredTiger (13) [1475058727:821829][6785:0x7fa9684ecc80], file:WiredTiger.wt, connection: /var/lib/mongodb/WiredTiger.turtle: handle-open: open: Permission denied
2016-09-28T11:32:07.822+0100 I - [initandlisten] Assertion: 28595:13: Permission denied
2016-09-28T11:32:07.822+0100 I STORAGE [initandlisten] exception in initAndListen: 28595 13: Permission denied, terminating
2016-09-28T11:32:07.822+0100 I CONTROL [initandlisten] dbexit: rc: 100
So the problem was in permissions on /var/lib/mongodb folder.
sudo chown -R mongodb:mongodb /var/lib/mongodb/
sudo chmod -R 755 /var/lib/mongodb
Fixed it, although I do realise that may be not too secure (it's my own dev box I'm in my case), bit following the change both db and authentication worked.
Upvotes: 4
Reputation: 379
Do ls -la
to know the user and group of /var/log/mongodb.
Then do sudo chown -R user:group /data/db
Now run sudo service mongodb start
.
Check the status with sudo service mongodb status
Upvotes: 0
Reputation: 81
For mac users:
Run ls -ld /data/db/
Output should be something like drwrx-xr-x 20 singh wheel 680 21 Jul 05:49 /data/db/
Where singh is the owner and wheel is the group it belongs to.
Run sudo chown -R singh:wheel /data/db
Run mongod
Upvotes: 7
Reputation: 1254
I was having the same problem on a Ubuntu ec2 instance. I was following this amazon article on page 7:
http://d36cz9buwru1tt.cloudfront.net/AWS_NoSQL_MongoDB.pdf
Mongodb path in /etc/mongodb.conf
was set to /var/lib/mongodb
(primary install location and working). When I changed to /data/db
(EBS volume) I was getting 'errno:13 Permission denied'.
sudo service mongodb stop
.ls -la
to see what group & owner mongodb assigned to /var/lib/mongodb
(existing path) and I changed the /data/db
(new path) with chown
and chgrp
to match. (example: sudo chown -R mongodb:mongodb /data/db
)etc/mongodb.conf
to /data/db
and deleted the old mongo files in /var/lib/mongodb
directory.sudo service mongodb start
and waited about a minute. If you try to connect to 27017 immediately you won't be able to./data/db
(EBS volume) and mongo should have placed a journal, mongod.lock, local.ns, local.0, etc. If not try sudo service mongodb restart
and check a minute later.I just spent over a hour with this. Changing the group and deleting the old files is probably not necessary, but that's what worked for me.
This is a great video about mounting a ebs volume to ec2 instance:
http://www.youtube.com/watch?v=gBII3o3BofU
Upvotes: 123
Reputation: 11027
In Mycase
In mongodb version 2.6.11 default databse directory is /var/lib/mongodb/
$ sudo chown -R id -u
/var/lib/mongodb/
$ sudo chown -R id -u
/var/lib/mongodb/mongod.lock
$ sudo /etc/init.d/mongod stop
$ sudo /etc/init.d/mongod start
Upvotes: 2
Reputation: 801
This is what I did to fix the problem:
$sudo mkdir -p /data/db
$export PATH=/usr/local/Cellar/mongodb/3.0.7/bin:$PATH
$sudo chown -R id -u
/data/db
and then to start mongo...
$mongod
Upvotes: 1
Reputation: 3092
You just have to give access to your /data/db
folder.
Type sudo chown -R <USERNAME> /data/db
, replace <USERNAME>
by your username.
You can find your username by typing whoami
.
Upvotes: 54
Reputation: 49
For those of you experiencing this error on Windows using Task Manager end the instance of "mongod.exe" that is running. Once that is done permanently delete the mongo.lock file and run mongod.exe. It should work perfectly after that.
Upvotes: 4
Reputation: 415
After I killed mongod, I just had the same problem: couldn't start mongod.
$> sudo kill `pidof mongod`
2015-08-03T05:58:41.339+0000 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/mongodbtest/replset/data/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
After I delete the lock directly, I can restart the mongod process.
$> rm -rf /data/mongodbtest/replset/data/mongod.lock
Upvotes: 1
Reputation: 466
I had a similar issue and followed all the instructions above regarding changing owners using sudo chown etc. I still had an instance of mongodb running in the background after the changes. Running
ps auxw | grep mongo
showed me other tasks using mongo running in background that weren't closed properly. I then ran kill on all the ones running and then could start my server.
Upvotes: 6
Reputation: 1908
I installed mongodb with EBS on an EC2 with Ubuntu 14.04 following this tutorial:
http://docs.mongodb.org/ecosystem/platforms/amazon-ec2/
But instead of the suggested chown I did:
sudo chown -R mongodb:mongodb /data /log /journal
To fix the problem
Upvotes: 12
Reputation: 39307
In my case the issue was solved by removing the log file.
sudo rm /log/mongod.log
Although the error message refers specifically to the lock file:
exception in initAndListen: 10309 Unable to create/open lock file:
/data/mongod.lock errno:13 Permission denied
Is a mongod instance already running?, terminating
Upvotes: 1
Reputation: 1582
Removing the mongodb.lock file was not the issue in my case. I did so and got an error about the port being in use: [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017. I found another solution here: unable to start mongodb local server with instructions to kill the process:
Find out from netstat which process is running mongodb port (27017)
sudo netstat -tulpn | grep :27017
Output will be: tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 1412/mongod
Kill the appropriate process.
sudo kill 1412
(replace 1412 with your process ID found in step 1)
And I was able to successfully start mongodb again. I believe mine was still running from an improper shut down.
Upvotes: 5
Reputation: 3789
On a Fedora 18 with Mongo 2.2.4 instance I was able to get around a similar error by disabling SELinux by calling setenforce 0
as root.
BTW, this was a corporate environment, not an Amazon EC2 instance, but the symptoms were similar.
Upvotes: 1
Reputation: 920
In my case (AWS EC2 instance, Ubuntu) helped:
$ sudo mkdir -p /data/db/
$ sudo chown `USERNAME` /data/db
And after that everything worked fine.
Upvotes: 84