mongodb 为什么我不能启动mongodb

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5798549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 12:04:49  来源:igfitidea点击:

why can't I start the mongodb

ubuntumongodb

提问by zjm1126

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

回答by Justin Jenkins

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

正在启动MongoDB中需要有用户帐户写权限/data/db/目录...你可以改变这个是这样的...

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

此命令会将 的所有者更改为/data/db/正在使用的用户帐户。

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

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

如果在启动 MongoDB 时仍然遇到问题,则需要删除/data/db/mongod.lock然后在数据库上运行修复...

mongod --repair

More about the repair command here.

有关修复命令的更多信息,请点击此处

回答by Austin Taylor

Either sudothe call to mongodor change the permissions of /data/db/mongod.lockso that it is writable by you.

无论是sudo在通话mongod或更改的权限/data/db/mongod.lock,以便它是你写的。

回答by Swathi

I resolved this by doing a chown on mongodb ie.

我通过在 mongodb 上做一个 chown 来解决这个问题,即。

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.

希望这可以帮助。

回答by Swathi

Make sure you do not have a mongod instance running.

确保您没有运行 mongod 实例。

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

这对我有用。我首先通过在终端中查看以下内容来检查是否有一个实例在后台运行: ps aux | grep mongo

and I saw that there was: 48358 bla bla mongod

我看到有:48358 bla bla mongod

so I killed it: kill 48358

所以我杀了它:kill 48358

and then I was able to run it fine.

然后我就可以正常运行了。

回答by Sanjay Jain

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
  1. 删除锁定文件后,我使用修复了它sudo mongod --repair --config=/etc/mongodb.conf,此后我使用检查了 mongod.lock 权限ls -l /var/lib/mongodb/mongod.lock
  2. 它显示 root 是锁定文件的所有者,所以我使用 sudo chown mongodb:mongodb /var/lib/mongodb/*
  3. 然后使用重新启动mongodb服务 sudo service mongodb restart

回答by andilabs

On Mac OSX Yosemite after standard install with brew:

在 Mac OSX Yosemite 上使用 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 PIDand run:

取值PID并运行:

kill -9 <PID>

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

现在您应该能够启动 mongo 服务器:mongod然后例如在单独的控制台窗口中连接到它mongo

回答by H6.

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

如果您想拯救副本集的成员,请不要使用上述方法。而是使用MongoDBReSync 文档中描述的过程。