mongodb Mongod 抱怨没有 /data/db 文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7948789/
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
Mongod complains that there is no /data/db folder
提问by Nik So
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.
我今天第一次使用我的新 Mac。我一直遵循 mongodb.org 上的入门指南,直到创建 /data/db 目录的步骤为止。顺便说一句,我使用了自制路线。
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.
所以我打开一个终端,我想我在你所谓的主目录中,因为当我执行“ls”时,我看到了桌面应用程序电影音乐图片文档和库的文件夹。
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.
工作。当我“ls”时,数据目录和嵌套在其中的 db 文件夹确实存在。
then I fire up mongod and it complains about not finding data/db
然后我启动 mongod,它抱怨找不到数据/数据库
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
当我执行“ls”时,我确实看到了数据目录和数据库目录。不过,在 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
EDIT Getting error message for
编辑获取错误消息
sudo chown mongod:mongod /data/db
chown: mongod: Invalid argument
Thanks, everyone!
谢谢大家!
回答by Tilo
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.
/data/db 意味着它直接位于“/”根目录下,而您创建的“data/db”(没有前导 /)可能只是在另一个目录中,例如“/root”主目录。
You need to create this directory as root
您需要以 root 身份创建此目录
Either you need to use sudo
, e.g. sudo mkdir -p /data/db
要么你需要使用sudo
,例如sudo mkdir -p /data/db
Or you need to do su -
to become superuser, and then create the directory with mkdir -p /data/db
或者你需要做su -
成为超级用户,然后用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.
MongoDB 也有一个选项,您可以在另一个位置创建数据目录,但这通常不是一个好主意,因为它只是使 DB 恢复等事情稍微复杂化,因为您总是必须手动指定 db-path。我不建议这样做。
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.
您收到的错误消息是“无法创建/打开锁定文件:/data/db/mongod.lock errno:13 Permission denied”。您创建的目录似乎没有正确的权限和所有权——它需要由运行 MongoDB 进程的用户写入。
To see the permissions and ownership of the '/data/db/' directory, do this: (this is what the permissions and ownership should look like)
要查看“/data/db/”目录的权限和所有权,请执行以下操作:(这是权限和所有权的样子)
$ 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.
左侧的“drwxr-xr-x”显示用户、组和其他人的权限。'mongod mongod' 显示谁拥有该目录,以及该目录属于哪个组。在这种情况下,两者都被称为“mongod”。
If your '/data/db' directory doesn't have the permissions and ownership above, do this:
如果您的“/data/db”目录没有上述权限和所有权,请执行以下操作:
First check what user and group your mongo user has:
首先检查你的 mongo 用户有什么用户和组:
# 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.
您应该在 /etc/passwd 中有一个 mongod 条目,因为它是一个守护进程。
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 )
您还可以使用用户名和组名,如下所示:(它们可以在 /etc/passwd 和 /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.
缺点是 $USER 是一个具有登录 shell 的帐户。出于安全原因,守护进程在理想情况下应该没有外壳,这就是为什么您在上面的密码文件的 grep 中看到 /bin/false 的原因。
Check here to better understand the meaning of the directory permissions:
检查这里以更好地理解目录权限的含义:
http://www.perlfect.com/articles/chmod.shtml
http://www.perlfect.com/articles/chmod.shtml
Maybe also check out one of the tutorials you can find via Google: "UNIX for beginners"
也许还可以查看您可以通过 Google 找到的教程之一:“UNIX 初学者”
回答by jagough
After getting the same error as Nik
在得到与 Nik 相同的错误后
chown: id -u: Invalid argument
chown: id -u: 无效参数
I found out this apparently occurred from using the wrong type of quotation marks (should have been backquotes) Ubuntu Forums
我发现这显然是由于使用了错误类型的引号(应该是反引号)而发生的Ubuntu 论坛
Instead I just used
相反,我只是用
sudo chown $USER /data/db
须藤 chown $USER /data/db
as an alternative and now mongod has the permissions it needs.
作为替代方案,现在 mongod 拥有所需的权限。
回答by Iman Mohamadi
This works for me, found in comments:
这对我有用,在评论中找到:
sudo chown -R $USER /data/db
回答by Connor Leech
Create the folder.
创建文件夹。
sudo mkdir -p /data/db/
Give yourself permission to the folder.
授予自己对该文件夹的权限。
sudo chown `id -u` /data/db
Then you can run mongod
without sudo
. Works on OSX Yosemite
然后你可以在mongod
没有sudo
. 适用于 OSX 优胜美地
回答by orluke
To fix that error on OS X, I restarted and stopped the service:
$ brew services restart mongodb
$ brew services stop mongodb
为了在 OS X 上修复该错误,我重新启动并停止了该服务:
$ brew services restart mongodb
$ brew services stop mongodb
Then I ran mongod --config /usr/local/etc/mongod.conf
, and the problem was gone.
然后我跑了mongod --config /usr/local/etc/mongod.conf
,问题就解决了。
The error seemed to arise after upgrading the mongodb homebrew package.
该错误似乎是在升级 mongodb homebrew 包后出现的。
回答by Gal Bracha
Installing through brew on Mac where YOUR_USER_NAME and staffis the group
在 Mac 上通过 brew 安装,其中 YOUR_USER_NAME 和员工是组
sudo mkdir -p /data/db
sudo chmod +x+r+w /data/db/
sudo touch /data/db/mongod.lock
sudo chown YOUR_USER_NAME:staff /data/db
sudo chmod +x+r+w /data/db/mongod.lock
sudo chown YOUR_USER_NAME:staff /data/db/mongod.lock
回答by loreii
If you run mongo without arguments it's assume you are running on the production machine so it's use the default locations.
如果您不带参数运行 mongo,则假定您在生产机器上运行,因此它使用默认位置。
for using your own database (dev or just a different one) :
使用您自己的数据库(开发或只是一个不同的):
./bin/mongod --dbpath ~/data/db
回答by Tal Delbari
I had this problem with an existing Mongodb setup. I'm still not sure why it happened, but for some reason the Mongod process couldn't find the mongod.config file. Because it could not find the config file it tried to find the DB files in /data/db, a folder that didn't exist. However, the config file was still available so I made sure the process has permissions to the config file and run the mongod process with the --config flag as follows:
我在现有的 Mongodb 设置中遇到了这个问题。我仍然不确定它为什么会发生,但由于某种原因,Mongod 进程找不到 mongod.config 文件。因为它找不到配置文件,它试图在 /data/db(一个不存在的文件夹)中找到 DB 文件。但是,配置文件仍然可用,因此我确保该进程对配置文件具有权限,并使用 --config 标志运行 mongod 进程,如下所示:
mongod --config /etc/mongod.conf
In the config file itself I had this setting:
在配置文件本身我有这个设置:
storage:
dbPath: /var/lib/mongodb
And this is how the process could find the real DB folder again.
这就是该过程如何再次找到真正的 DB 文件夹。
回答by emrys57
I did
我做了
brew install mongodb
on 2018-02-01 and that gave me mongodb
version 3.6.2.
在 2018 年 2 月 1 日,这给了我mongodb
3.6.2 版。
Prompted by the answer from orlukeabove, I tried just
$ brew services restart mongodb
and everything sprang into life. My mongoose.createConnection()
call did what I wanted. The GUI MongoDB Compass, the community version, would connect. I used Compass to look at the local.startup_log
collection. That had one document in, the log of me just starting the mongoDB service, and that had
一切都变成了生命。我的mongoose.createConnection()
电话做了我想要的。该GUI MongoDB的指南针,社区版,将连接。我用 Compass 来查看local.startup_log
收藏。里面有一个文档,我刚刚启动 mongoDB 服务的日志,还有
cmdLine:Object
config:"/usr/local/etc/mongod.conf"
and indeed there was such a file:
确实有这样一个文件:
$ more /usr/local/etc/mongod.conf
systemLog:
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /usr/local/var/mongodb
net:
bindIp: 127.0.0.1
and there was a /usr/local/var/mongodb
directory with lots of obscure files. So that seems to be how the installation works now.
并且有一个/usr/local/var/mongodb
包含许多晦涩文件的目录。所以这似乎是现在安装的工作方式。
I'm not sure if brew services restart
sets the service to run at login. So I did
我不确定是否brew services restart
将服务设置为在登录时运行。所以我做了
brew services stop mongodb
brew services start mongodb
and hoped that starts it again after reboot. And, indeed, it did. In fact, now, I think the right thing to do after the initial installation is
并希望重新启动后再次启动它。而且,确实如此。事实上,现在,我认为在初始安装后正确的做法是
brew services start mongodb
and that should start the service and restart it after reboot.
这应该启动服务并在重新启动后重新启动它。
回答by Russell
Your command will have created the directory structure in the current folder, not the root directory of your computer (which is what the missing /
is).
您的命令将在当前文件夹中创建目录结构,而不是您计算机的根目录(这是缺少/
的)。
The first command was right, but because you are trying to create a folder in /
, which is a protected directory, you need to prefix it with sudo
, which is short for "superuser do". You'll then be asked for your password.
第一个命令是正确的,但是因为您要在/
受保护的目录中创建一个文件夹,所以您需要在它前面加上前缀sudo
,它是“超级用户 do”的缩写。然后系统会要求您输入密码。
So the full command would be:
所以完整的命令是:
$ sudo mkdir -p /data/db