无法在Mac OS X上运行mongodb

时间:2014-09-27 09:33:53

标签: macos mongodb homebrew

我使用mongodb安装了homebrewmongo命令在终端中按预期运行,但是当我在终端中运行mongod时,它返回:

mongod --help for help and startup options
2014-09-27T12:55:42.705+0330 [initandlisten] MongoDB starting : pid=3704 port=27017 dbpath=/data/db 64-bit host=Your-MacBook-Pro.local
2014-09-27T12:55:42.705+0330 [initandlisten] 
2014-09-27T12:55:42.705+0330 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2014-09-27T12:55:42.705+0330 [initandlisten] db version v2.6.4
2014-09-27T12:55:42.705+0330 [initandlisten] git version: nogitversion
2014-09-27T12:55:42.705+0330 [initandlisten] build info: Darwin Your-MacBook-Pro.local 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
2014-09-27T12:55:42.705+0330 [initandlisten] allocator: tcmalloc
2014-09-27T12:55:42.705+0330 [initandlisten] options: {}
2014-09-27T12:55:42.706+0330 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2014-09-27T12:55:42.706+0330 [initandlisten] dbexit: 
2014-09-27T12:55:42.706+0330 [initandlisten] shutdown: going to close listening sockets...
2014-09-27T12:55:42.706+0330 [initandlisten] shutdown: going to flush diaglog...
2014-09-27T12:55:42.706+0330 [initandlisten] shutdown: going to close sockets...
2014-09-27T12:55:42.706+0330 [initandlisten] shutdown: waiting for fs preallocator...
2014-09-27T12:55:42.706+0330 [initandlisten] shutdown: lock for final commit...
2014-09-27T12:55:42.706+0330 [initandlisten] shutdown: final commit...
2014-09-27T12:55:42.706+0330 [initandlisten] shutdown: closing all files...
2014-09-27T12:55:42.706+0330 [initandlisten] closeAllFiles() finished
2014-09-27T12:55:42.706+0330 [initandlisten] shutdown: removing fs lock...
2014-09-27T12:55:42.706+0330 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
2014-09-27T12:55:42.706+0330 [initandlisten] dbexit: really exiting now

所以我不能在我的php应用程序中使用mongo类。是由一些端口冲突引起的吗?这有什么解决方案吗?

2 个答案:

答案 0 :(得分:5)

如果您看到异常,则说:

exception in initAndListen: 
10309 Unable to create/open lock file: /data/db/mongod.lock 
errno:13 Permission denied Is a mongod instance already running?, terminating

mongod实例无法创建锁定文件或该位置已存在锁定文件,并且由于先前运行的mongod实例的不正确终止/关闭,当前实例无法获取它。

要解决此问题,请手动删除/data/db/mongod.lock(如果存在)并重新启动mongod服务。

sudo rm /data/db/mongod.lock

如果锁定文件不存在,请提供/data/db目录的读/写权限并重新启动实例。

答案 1 :(得分:0)

我认为它需要管理员权限。

我用过:sudo mongod,它对我来说很好用。请试一试。