mongodb 无法创建/打开锁定文件:/data/mongod.lock errno:13 权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15229412/
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
Unable to create/open lock file: /data/mongod.lock errno:13 Permission denied
提问by Tampa
How to I get mongo to use a mounted drive on ec2? I really do not understand. I attached a volume on ec2 formatted the drive as root and start as root and yet as root I cant access? I am running on ubuntu 12.04. No other mongo is running
如何让 mongo 在 ec2 上使用已安装的驱动器?我真的不明白。我在 ec2 上附加了一个卷,将驱动器格式化为 root 并以 root 启动,但作为 root 我无法访问?我在 ubuntu 12.04 上运行。没有其他 mongo 正在运行
I see that mongo made a 'db' dir in /data i.e. /data/db
我看到 mongo 在 /data ie /data/db 中创建了一个“db”目录
cd /
ls -al
drwxr-xr-x 4 root root 4096 Mar 5 16:28 data
cd /data
ls -al
total 28
drwxr-xr-x 4 root root 4096 Mar 5 16:28 .
drwxr-xr-x 24 root root 4096 Mar 5 16:28 ..
drwxr-xr-x 2 root root 4096 Mar 5 16:28 db
drwx------ 2 root root 16384 Mar 5 16:20 lost+found
sudo mkfs.ext3 /dev/xvdh
sudo mkdir /data
sudo su - -c 'echo "/dev/xvdh %s auto noatime 0 0" | sudo tee -a /etc/fstab'
sudo mount /data
sudo service mongodb start
mongodb start/running, process 17169
sudo ps -ef | grep mongod
ubuntu 15763 15634 0 16:32 pts/2 00:00:00 tail -f mongodb.log
ubuntu 18049 15766 0 16:43 pts/3 00:00:00 grep --color=auto mongod
Tue Mar 5 16:33:15 [initandlisten] MongoDB starting : pid=15890 port=27017 dbpath=/data 64-bit host=aws-mongo-server-east-staging-20130305161917
Tue Mar 5 16:33:15 [initandlisten] db version v2.2.3, pdfile version 4.5
Tue Mar 5 16:33:15 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
Tue Mar 5 16:33:15 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Tue Mar 5 16:33:15 [initandlisten] options: { bind_ip: "10.157.60.27", config: "/etc/mongodb.conf", dbpath: "/data", logappend: "true", logpath: "/var/log/mongodb/mongodb.log", replSet: "heythat" }
Tue Mar 5 16:33:15 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Tue Mar 5 16:33:15 dbexit:
Tue Mar 5 16:33:15 [initandlisten] shutdown: going to close listening sockets...
Tue Mar 5 16:33:15 [initandlisten] shutdown: going to flush diaglog...
Tue Mar 5 16:33:15 [initandlisten] shutdown: going to close sockets...
Tue Mar 5 16:33:15 [initandlisten] shutdown: waiting for fs preallocator...
Tue Mar 5 16:33:15 [initandlisten] shutdown: lock for final commit...
Tue Mar 5 16:33:15 [initandlisten] shutdown: final commit...
Tue Mar 5 16:33:15 [initandlisten] shutdown: closing all files...
Tue Mar 5 16:33:15 [initandlisten] closeAllFiles() finished
Tue Mar 5 16:33:15 [initandlisten] shutdown: removing fs lock...
Tue Mar 5 16:33:15 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Tue Mar 5 16:33:15 dbexit: really exiting now
Below is if I restart when I remove a lock file....
下面是如果我在删除锁定文件时重新启动....
Tue Mar 5 16:59:15 [initandlisten] MongoDB starting : pid=21091 port=27017 dbpath=/data 64-bit host=aws-mongo-server-east-staging-20130305161917
Tue Mar 5 16:59:15 [initandlisten] db version v2.2.3, pdfile version 4.5
Tue Mar 5 16:59:15 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
Tue Mar 5 16:59:15 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Tue Mar 5 16:59:15 [initandlisten] options: { bind_ip: "10.157.60.27", config: "/etc/mongodb.conf", dbpath: "/data", logappend: "true", logpath: "/var/log/mongodb/mongodb.log", replSet: "heythat" }
Tue Mar 5 16:59:15 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Tue Mar 5 16:59:15 dbexit:
Tue Mar 5 16:59:15 [initandlisten] shutdown: going to close listening sockets...
Tue Mar 5 16:59:15 [initandlisten] shutdown: going to flush diaglog...
Tue Mar 5 16:59:15 [initandlisten] shutdown: going to close sockets...
Tue Mar 5 16:59:15 [initandlisten] shutdown: waiting for fs preallocator...
Tue Mar 5 16:59:15 [initandlisten] shutdown: lock for final commit...
Tue Mar 5 16:59:15 [initandlisten] shutdown: final commit...
Tue Mar 5 16:59:15 [initandlisten] shutdown: closing all files...
Tue Mar 5 16:59:15 [initandlisten] closeAllFiles() finished
Tue Mar 5 16:59:15 [initandlisten] shutdown: removing fs lock...
Tue Mar 5 16:59:15 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Tue Mar 5 16:59:15 dbexit: really exiting now
采纳答案by Randy Swanson
I was having the same problem on a Ubuntu ec2 instance. I was following this amazon article on page 7:
我在 Ubuntu ec2 实例上遇到了同样的问题。我正在关注第 7 页上的这篇亚马逊文章:
http://d36cz9buwru1tt.cloudfront.net/AWS_NoSQL_MongoDB.pdf
http://d36cz9buwru1tt.cloudfront.net/AWS_NoSQL_MongoDB.pdf
Mongodb path in /etc/mongodb.conf
was set to /var/lib/mongodb
(primary install location and working). When I changed to /data/db
(EBS volume) I was getting 'errno:13 Permission denied'.
Mongodb 路径/etc/mongodb.conf
设置为/var/lib/mongodb
(主要安装位置和工作)。当我更改为/data/db
(EBS volume) 时,我收到“errno:13 Permission denied”。
- First I ran
sudo service mongodb stop
. - Then I used
ls -la
to see what group & owner mongodb assigned to/var/lib/mongodb
(existing path) and I changed the/data/db
(new path) withchown
andchgrp
to match. (example:sudo chown -R mongodb:mongodb /data/db
) - Then I updated the path in
etc/mongodb.conf
to/data/db
and deleted the old mongo files in/var/lib/mongodb
directory. - Then I ran
sudo service mongodb start
and waited about a minute. If you try to connect to 27017 immediately you won't be able to. - After a minute check
/data/db
(EBS volume) and mongo should have placed a journal, mongod.lock, local.ns, local.0, etc. If not trysudo service mongodb restart
and check a minute later.
- 首先我跑了
sudo service mongodb stop
。 - 然后我用
ls -la
看哪个组和所有者的MongoDB分配/var/lib/mongodb
(现有路径),我改变了/data/db
(新路),与chown
和chgrp
相匹配。(例如:sudo chown -R mongodb:mongodb /data/db
) - 然后,我更新的路径
etc/mongodb.conf
,以/data/db
在删除旧的蒙戈文件/var/lib/mongodb
目录。 - 然后我跑了
sudo service mongodb start
,等了大约一分钟。如果您尝试立即连接到 27017,您将无法连接。 - 一分钟后检查
/data/db
(EBS 卷)和 mongo 应该已经放置了一个日志,mongod.lock,local.ns,local.0 等。如果没有sudo service mongodb restart
,一分钟后尝试检查。
I just spent over a hour with this. Changing the group and deleting the old files is probably not necessary, but that's what worked for me.
我只花了一个多小时。更改组和删除旧文件可能没有必要,但这对我有用。
This is a great video about mounting a ebs volume to ec2 instance:
这是一个关于将 ebs 卷安装到 ec2 实例的精彩视频:
回答by Haimei
I use this method to solve the problem:
我用这个方法来解决问题:
sudo chown -R mongodb:mongodb /data/db
回答by Belhor
In my case (AWS EC2 instance, Ubuntu) helped:
在我的情况下(AWS EC2 实例,Ubuntu)帮助:
$ sudo mkdir -p /data/db/
$ sudo chown `USERNAME` /data/db
And after that everything worked fine.
之后一切正常。
回答by julien bouteloup
You just have to give access to your /data/db
folder.
您只需要授予对/data/db
文件夹的访问权限。
Type sudo chown -R <USERNAME> /data/db
, replace <USERNAME>
by your username.
输入sudo chown -R <USERNAME> /data/db
,替换<USERNAME>
为您的用户名。
You can find your username by typing whoami
.
您可以通过键入来找到您的用户名whoami
。
回答by Evers
I installed mongodb with EBS on an EC2 with Ubuntu 14.04 following this tutorial:
我按照本教程在带有 Ubuntu 14.04 的 EC2 上安装了带有 EBS 的 mongodb:
http://docs.mongodb.org/ecosystem/platforms/amazon-ec2/
http://docs.mongodb.org/ecosystem/platforms/amazon-ec2/
But instead of the suggested chown I did:
但是我没有建议使用 chown:
sudo chown -R mongodb:mongodb /data /log /journal
To fix the problem
解决问题
回答by Venky Soorisetty
I had similar issue, the actual reason was that there was mongod session running already from my previous attempt.
我有类似的问题,实际原因是我之前的尝试已经运行了 mongod 会话。
I ran
我跑了
killall mongod
and everything else ran just as expected.
其他一切都按预期运行。
killall
command would send a TERM signal to all processes with a real UID. So this kills all the running instances of mongod so that you could start your own.
killall
命令会向所有具有真实 UID 的进程发送 TERM 信号。所以这会杀死所有正在运行的 mongod 实例,以便您可以启动自己的实例。
回答by Abdullah
As of today, I tried to get my way through the to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating, and tried all the answer posted above to solve this problem, hence nothing worked out by adding
截至今天,我试图通过创建/打开锁定文件:/data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating,并尝试了上面发布的所有答案解决了这个问题,因此通过添加没有任何效果
sudo chown -R mongodb:mongodb /data/db
须藤 chown -R mongodb:mongodb /data/db
Unless I added my current user permission to the location path by
除非我将当前用户权限添加到位置路径
sudo chown $USER /data/db
须藤 chown $USER /data/db
Hope this helps someone. Also I just installed Mongo DB on my pi. Cheers!
希望这可以帮助某人。另外我刚刚在我的 pi 上安装了 Mongo DB。干杯!
回答by amanSingh
For mac users:
Run ls -ld /data/db/
Output should be something like drwrx-xr-x 20 singh wheel 680 21 Jul 05:49 /data/db/
Where singhis the owner and wheelis the group it belongs to.
Run sudo chown -R singh:wheel /data/db
Run mongod
对于 mac 用户:
运行ls -ld /data/db/
输出应该类似于drwrx-xr-x 20 singh wheel 680 21 Jul 05:49 /data/db/
其中singh是所有者,而wheel是它所属的组.
运行sudo chown -R singh:wheel /data/db
运行mongod
回答by Eugene G
I had a similar issue and followed all the instructions above regarding changing owners using sudo chown etc. I still had an instance of mongodb running in the background after the changes. Running
我有一个类似的问题,并按照上面有关使用 sudo chown 等更改所有者的所有说明进行操作。更改后,我仍然有一个 mongodb 实例在后台运行。跑步
ps auxw | grep mongo
showed me other tasks using mongo running in background that weren't closed properly. I then ran kill on all the ones running and then could start my server.
向我展示了使用 mongo 在后台运行但未正确关闭的其他任务。然后我在所有正在运行的服务器上运行 kill 然后可以启动我的服务器。
回答by Casey Murray
Removing the mongodb.lock file was not the issue in my case. I did so and got an error about the port being in use: [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017. I found another solution here: unable to start mongodb local serverwith instructions to kill the process:
在我的情况下,删除 mongodb.lock 文件不是问题。我这样做了,但收到有关正在使用的端口的错误:[initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017。我在这里找到了另一个解决方案:无法使用终止进程的指令启动 mongodb 本地服务器:
Find out from netstat which process is running mongodb port (27017)
sudo netstat -tulpn | grep :27017
Output will be: tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 1412/mongod
Kill the appropriate process.
sudo kill 1412
(replace 1412 with your process ID found in step 1)
从 netstat 找出哪个进程正在运行 mongodb 端口 (27017)
sudo netstat -tulpn | grep :27017
输出将是:tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 1412/mongod
杀死相应的进程。
sudo kill 1412
(将 1412 替换为您在步骤 1 中找到的进程 ID)
And I was able to successfully start mongodb again. I believe mine was still running from an improper shut down.
我能够再次成功启动mongodb。我相信我的仍然因不当关闭而运行。