今天我第一次用我的新mac电脑。我遵循mongodb.org上的入门指南,直到创建/data/db目录的步骤。顺便说一句,我用的是自制路线。

所以我打开一个终端,我认为我在你所谓的主目录,因为当我按“ls”时,我看到桌面应用程序、电影、音乐、图片、文档和库的文件夹。

所以我做了一个

mkdir -p /data/db

首先,它说许可被拒绝。我不停地尝试了半个小时,最后:

mkdir -p data/db

工作。当我“ls”,一个目录的数据和嵌套在其中的db文件夹确实存在。

然后我启动mongod,它抱怨找不到data/db

我做错什么了吗?

现在我已经完成了

sudo mkdir -p /data/db

当我执行“ls”时,我确实看到了data dir和db dir。在db目录下,什么都没有,当我运行mongod

Sun Oct 30 19:35:19 [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
Sun Oct 30 19:35:19 dbexit: 
Sun Oct 30 19:35:19 [initandlisten] shutdown: going to close listening sockets...
Sun Oct 30 19:35:19 [initandlisten] shutdown: going to flush diaglog...
Sun Oct 30 19:35:19 [initandlisten] shutdown: going to close sockets...
Sun Oct 30 19:35:19 [initandlisten] shutdown: waiting for fs preallocator...
Sun Oct 30 19:35:19 [initandlisten] shutdown: lock for final commit...
Sun Oct 30 19:35:19 [initandlisten] shutdown: final commit...
Sun Oct 30 19:35:19 [initandlisten] shutdown: closing all files...
Sun Oct 30 19:35:19 [initandlisten] closeAllFiles() finished
Sun Oct 30 19:35:19 [initandlisten] shutdown: removing fs lock...
Sun Oct 30 19:35:19 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Sun Oct 30 19:35:19 dbexit: really exiting now

编辑 获取错误消息

sudo chown mongod:mongod /data/db

chown: mongod: Invalid argument

谢谢,大家好!


当前回答

我在现有的Mongodb设置中遇到了这个问题。我仍然不确定为什么会发生这种情况,但出于某种原因,Mongod进程无法找到Mongod。配置文件。 因为它找不到配置文件,所以它试图在/data/ DB文件夹中找到DB文件,这个文件夹不存在。 然而,配置文件仍然可用,所以我确保该进程具有配置文件的权限,并使用——config标志运行mongod进程,如下所示:

mongod --config /etc/mongod.conf

在配置文件本身,我有这样的设置:

storage:
  dbPath: /var/lib/mongodb

这就是进程如何再次找到真正的DB文件夹。

其他回答

通过使用窗口管理器创建/data/db文件夹,我解决了这个完全相同的问题。我一开始尝试通过终端来做,为了在根目录中创建一个文件夹,我必须使用sudo。

我用Finder找到了根目录,然后用“new folder”创建了一个新文件夹。对我来说完全管用。

注意:我使用的是OSX。

简单说明一下:

If you tried running mongod without changing the permissions first, you'll likely have a mongod.lock file (and some other files) in the /data/db directory. Even after you change the permissions for the /data/db directory to give access to your $USER, you'll continue to get the "Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied" error. Run ls -al /data/db and you'll probably see that the permissions for the individual files are still set to root for user, not to your $USER. You should remove the mongod.lock file, and the others as well. Then when you run mongod again, everything should work, and you can verify that the file permissions match the directory permissions by running ls -al again.

这个解决办法解决了我的问题

创建一个目录 Sudo mkdir -p /data/db .使用实例 这将使一个目录命名为db,然后尝试用命令开始 sudo mongod

如果你在启动mongod时遇到其他错误或问题,你可能会发现问题as

设置listener: SocketException:地址已被使用失败 如果你发现另一个错误,那么你必须通过输入到terminal as来终止mongod的运行进程

ps ax | grep mongod
sudo kill ps_number

并找到mongod运行端口并终止进程。 另一种方法是在启动mongod as时创建一个特定的端口

sudo mongod --port 27018

在终端上输入“id”查看可用的用户id, 然后简单地输入

"sudo chown -R idname /data/db"

这对我来说很有效! 希望这能解决你的问题。

为了在OS X上修复这个错误,我重新启动并停止了服务: $ brew服务重启mongodb $ brew服务停止mongodb

然后我运行mongod——config /usr/local/etc/mongod.conf,问题就解决了。

该错误似乎是在升级mongodb自制包后出现的。