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

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

问题描述

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

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.

所以我打开一个终端,我觉得我在您称为主目录的位置,因为当我"ls"执行操作时,我会看到桌面应用程序电影"音乐图片"文档和库的文件夹.

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.

所以我做了

mkdir -p /data/db

首先,它说许可被拒绝.我半小时不停地尝试不同的事情,最后:

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

mkdir -p data/db

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

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

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

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

我做错了什么吗?

现在我已经完成

sudo mkdir -p /data/db

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

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

谢谢大家!

推荐答案

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

/data/db表示它直接位于"/"根目录下,而您可能只是在另一个目录(例如"/root"主目录)内创建了"data/db"(不带前导/).

/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.

您需要以根用户身份创建此目录

您需要使用sudo,例如sudo mkdir -p /data/db

或者您需要执行su -成为超级用户,然后使用mkdir -p /data/db

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

注意:

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

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.

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

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.

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

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/

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

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.

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

首先检查您的mongo用户拥有哪些用户和组:

First check what user and group your mongo user has:

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

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

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

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

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

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

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

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

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

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

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

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