Mongod 抱怨没有/data/db 文件夹 [英] Mongod complains that there is no /data/db folder

查看:38
本文介绍了Mongod 抱怨没有/data/db 文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天第一次使用我的新 Mac.我遵循 mongodb.org 上的入门指南,直到创建/data/db 目录的步骤为止.顺便说一句,我使用了自制路线.

所以我打开一个终端,我想我在你所谓的主目录,因为当我执行ls"时,我看到了桌面应用程序电影音乐图片文档和库的文件夹.

所以我做了一个

mkdir -p/data/db

首先,它说权限被拒绝.我一直尝试不同的东西半小时,最后:

mkdir -p 数据/db

工作了.当我ls"时,一个数据目录并嵌套在其中一个 db 文件夹确实存在.

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

我做错了吗?

现在我已经完成了

sudo mkdir -p/data/db

当我执行ls"时,我确实看到了数据目录和数据库目录.不过,在 db 目录中,绝对没有任何内容,当我现在运行 mongod 时

Sun Oct 30 19:35:19 [initandlisten] initAndListen 异常:10309 无法创建/打开锁文件:/data/db/mongod.lock errno:13 权限被拒绝 mongod 实例是否已在运行?, 终止10 月 30 日星期日 19:35:19 dbexit:Sun Oct 30 19:35:19 [initandlisten] 关机:要关闭监听套接字...Sun Oct 30 19:35:19 [initandlisten] 关机:要刷新对话框...Sun Oct 30 19:35:19 [initandlisten] 关机:要关闭套接字...Sun Oct 30 19:35:19 [initandlisten] 关机:等待 fs 预分配器...Sun Oct 30 19:35:19 [initandlisten] 关机:锁定最终提交...Sun Oct 30 19:35:19 [initandlisten] 关闭:最终提交...Sun Oct 30 19:35:19 [initandlisten] 关机:关闭所有文件...Sun Oct 30 19:35:19 [initandlisten] closeAllFiles() 完成Sun Oct 30 19:35:19 [initandlisten] 关机:移除 fs 锁...Sun Oct 30 19:35:19 [initandlisten] 无法删除 fs lock errno:9 错误的文件描述符Sun Oct 30 19:35:19 dbexit:现在真的退出了

编辑获取错误信息

sudo chown mongod:mongod/data/dbchown: mongod: 无效参数

谢谢大家!

解决方案

您在错误的位置创建了目录

/data/db 意味着它直接位于/"根目录下,而您创建的data/db"(没有前导/)可能只是在另一个目录中,例如/root"主目录.

您需要以 root 身份创建此目录

或者你需要使用 sudo ,例如sudo mkdir -p/data/db

或者你需要做su -成为超级用户,然后用mkdir -p/data/db

创建目录<小时>

注意:

MongoDB 也有一个选项,您可以在其中创建数据目录在另一个位置,但这通常不是一个好主意,因为它只是使数据库恢复等事情稍微复杂化,因为您总是必须手动指定 db-path.我不建议这样做.

<小时>

您收到的错误消息是无法创建/打开锁定文件:/data/db/mongod.lock errno:13 Permission denied".您创建的目录似乎没有正确的权限和所有权——需要运行MongoDB进程的用户可写.

要查看/data/db/"目录的权限和所有权,请执行以下操作:(这是权限和所有权的样子)

$ ls -ld/data/db/drwxr-xr-x 4 mongod mongod 4096 Oct 26 10:31/data/db/

左侧的drwxr-xr-x"显示用户、组和其他人的权限.'mongod mongod' 显示谁拥有该目录,以及该目录属于哪个组.在这种情况下,两者都被称为mongod".

如果您的/data/db"目录没有上述权限和所有权,请执行此操作:

首先检查你的 mongo 用户有什么用户和组:

# grep mongo/etc/passwdmongod:x:498:496:mongod:/var/lib/mongo:/bin/false

您应该在/etc/passwd 中有一个 mongod 条目,因为它是一个守护进程.

sudo chmod 0755/data/dbsudo chown -R 498:496/data/db # 使用 user-id , group-id

您也可以使用用户名和组名,如下:(它们可以在/etc/passwd 和/etc/group 中找到)

sudo chown -R mongod:mongod/data/db

这应该让它起作用..

在下面的评论中,有些人使用了这个:

sudo chown -R `id -u`/data/db须藤 chmod -R go+w/data/db

sudo chown -R $USER/data/db须藤 chmod -R go+w/data/db

缺点是 $USER 是一个有登录 shell 的帐户.出于安全原因,守护进程在理想情况下应该没有外壳,这就是为什么您在上面的密码文件的 grep 中看到/bin/false 的原因.

查看这里以更好地理解目录权限的含义:

http://www.perlfect.com/articles/chmod.shtml

也许还可以查看您可以通过 Google 找到的教程之一:UNIX 初学者"

I am using my new mac for the first time today. I am following the get started guide on the mongodb.org up until the step where one creates the /data/db directory. btw, I used the homebrew route.

So I open a terminal, and I think I am at what you called the Home Directory, for when I do "ls", I see folders of Desktop Application Movies Music Pictures Documents and Library.

So I did a

mkdir -p /data/db

first, it says permission denied. I kept trying different things for half and hour and finally :

mkdir -p data/db

worked. and when I "ls", a directory of data and nested in it a db folder do exist.

then I fire up mongod and it complains about not finding data/db

Have I done something wrong?

Now I have done the

sudo mkdir -p /data/db

and when I do a "ls" I do see the data dir and the db dir. inside the db dir though, there is absolutely nothing in it and when I now run 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

EDIT Getting error message for

sudo chown mongod:mongod /data/db

chown: mongod: Invalid argument

Thanks, everyone!

解决方案

You created the directory in the wrong place

/data/db means that it's directly under the '/' root directory, whereas you created 'data/db' (without the leading /) probably just inside another directory, such as the '/root' homedirectory.

You need to create this directory as root

Either you need to use sudo , e.g. sudo mkdir -p /data/db

Or you need to do su - to become superuser, and then create the directory with mkdir -p /data/db


Note:

MongoDB also has an option where you can create the data directory in another location, but that's generally not a good idea, because it just slightly complicates things such as DB recovery, because you always have to specify the db-path manually. I wouldn't recommend doing that.


Edit:

the error message you're getting is "Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied". The directory you created doesn't seem to have the correct permissions and ownership -- it needs to be writable by the user who runs the MongoDB process.

To see the permissions and ownership of the '/data/db/' directory, do this: (this is what the permissions and ownership should look like)

$ ls -ld /data/db/
drwxr-xr-x 4 mongod mongod 4096 Oct 26 10:31 /data/db/

The left side 'drwxr-xr-x' shows the permissions for the User, Group, and Others. 'mongod mongod' shows who owns the directory, and which group that directory belongs to. Both are called 'mongod' in this case.

If your '/data/db' directory doesn't have the permissions and ownership above, do this:

First check what user and group your mongo user has:

# grep mongo /etc/passwd
mongod:x:498:496:mongod:/var/lib/mongo:/bin/false

You should have an entry for mongod in /etc/passwd , as it's a daemon.

sudo chmod 0755 /data/db
sudo chown -R 498:496 /data/db    # using the user-id , group-id

You can also use the user-name and group-name, as follows: (they can be found in /etc/passwd and /etc/group )

sudo chown -R mongod:mongod /data/db 

that should make it work..

In the comments below, some people used this:

sudo chown -R `id -u` /data/db
sudo chmod -R go+w /data/db

or

sudo chown -R $USER /data/db 
sudo chmod -R go+w /data/db

The disadvantage is that $USER is an account which has a login shell. Daemons should ideally not have a shell for security reasons, that's why you see /bin/false in the grep of the password file above.

Check here to better understand the meaning of the directory permissions:

http://www.perlfect.com/articles/chmod.shtml

Maybe also check out one of the tutorials you can find via Google: "UNIX for beginners"

这篇关于Mongod 抱怨没有/data/db 文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆