why can't I start the mongodb

2019-01-12 23:37发布

问题:

this is the error:

(mysite)zjm1126@zjm1126-G41MT-S2:~$ /usr/local/mongodb/bin/mongod 
/usr/local/mongodb/bin/mongod --help for help and startup options
Wed Apr 27 10:02:41 [initandlisten] MongoDB starting : pid=2652 port=27017 dbpath=/data/db/ 32-bit 

** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
**       see http://blog.mongodb.org/post/137788967/32-bit-limitations
**       with --dur, the limit is lower

Wed Apr 27 10:02:41 [initandlisten] db version v1.8.1, pdfile version 4.5
Wed Apr 27 10:02:41 [initandlisten] git version: a429cd4f535b2499cc4130b06ff7c26f41c00f04
Wed Apr 27 10:02:41 [initandlisten] build sys info: Linux bs-linux32.10gen.cc 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_37
Wed Apr 27 10:02:41 [initandlisten] exception in initAndListen std::exception: Unable to create / open lock file for lockfilepath: /data/db/mongod.lock errno:13 Permission denied, terminating
Wed Apr 27 10:02:41 dbexit: 
Wed Apr 27 10:02:41 [initandlisten] shutdown: going to close listening sockets...
Wed Apr 27 10:02:41 [initandlisten] shutdown: going to flush diaglog...
Wed Apr 27 10:02:41 [initandlisten] shutdown: going to close sockets...
Wed Apr 27 10:02:41 [initandlisten] shutdown: waiting for fs preallocator...
Wed Apr 27 10:02:41 [initandlisten] shutdown: closing all files...
Wed Apr 27 10:02:41 closeAllFiles() finished
Wed Apr 27 10:02:41 [initandlisten] shutdown: removing fs lock...
Wed Apr 27 10:02:41 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Wed Apr 27 10:02:41 dbexit: really exiting now

回答1:

The user account that is starting MongoDB needs to have write privileges to the /data/db/ directory ... you can change this like so ...

This command will change the owner of the /data/db/ to the user account being used.

$ sudo chown `id -u` /data/db
$ mongod 

If you still run into problems with MongoDB starting, you need to delete /data/db/mongod.lock and then run repair on your database ...

mongod --repair

More about the repair command here.



回答2:

Either sudo the call to mongod or change the permissions of /data/db/mongod.lock so that it is writable by you.



回答3:

I resolved this by doing a chown on mongodb ie.

sudo chown -R mongodb:mongodb /data

This is because, when you do

ls -lrth /data
drwxr-xr-x 2 mongodb mongodb  6 Jan  5 02:31 journal
-rwxr-xr-x 1 mongodb mongodb  0 Jan  5 02:31 mongod.lock
drwxr-xr-x 2 ubuntu  root    24 May  8 20:02 configdb

Hope this helps.



回答4:

Make sure you do not have a mongod instance running.

This is what worked for me. I checked to see if there was an instance running in the background at first by looking in the terminal like this: ps aux | grep mongo

and I saw that there was: 48358 bla bla mongod

so I killed it: kill 48358

and then I was able to run it fine.



回答5:

Here, how i solved it

  1. After removing lock file I repaired it using sudo mongod --repair --config=/etc/mongodb.conf, After this I Checked mongod.lock permission using ls -l /var/lib/mongodb/mongod.lock
  2. it was showing root is owner of lock file, so i changed it back to mongodb using sudo chown mongodb:mongodb /var/lib/mongodb/*
  3. then restart mongodb service using sudo service mongodb restart


回答6:

If you want to rescue a member of a replica set don't use this methods described above. Instead use the procedures described in the ReSync-documentation of MongoDB.



回答7:

On Mac OSX Yosemite after standard install with brew:

sudo chown -R `id -u` /data/db

if it not starts (check if there are no hanging and blocking connections):

lsof -i:27017

outputs something like:

COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
mongod  16948 andi    8u  IPv4 0x883a71bc9412939d      0t0  TCP *:27017 (LISTEN)

take value of PID and run:

kill -9 <PID>

now you should be able to start mongo server: mongod and then e.g in separate console window connect to it with mongo