MongoDB 3.0 中的“无法取消链接套接字文件”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29813648/
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
'Failed to unlink socket file" error in MongoDB 3.0
提问by KurioZ7
I am new to MongoDB. I am trying to install MongoDb 3.0 on Ubuntu 13.0 LTS, which is a VM on Windows 7 Host. I have installed MongoDB successfully (packages etc.), but when I execute the command sudo service mongod start
, I get the following error in the "/var/log/mongodb/mongod.log" log file. Can anyone help me understanding this error. There is nothing on internet related to this.
我是 MongoDB 的新手。我正在尝试在 Ubuntu 13.0 LTS 上安装 MongoDb 3.0,它是 Windows 7 主机上的 VM。我已经成功安装了 MongoDB(包等),但是当我执行命令时sudo service mongod start
,我在“/var/log/mongodb/mongod.log”日志文件中收到以下错误。谁能帮我理解这个错误。互联网上没有任何与此相关的内容。
2015-04-23T00:12:00.876-0400 I CONTROL ***** SERVER RESTARTED ***** 2015-04-23T00:12:00.931-0400 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted 2015-04-23T00:12:00.931-0400 I - [initandlisten] Fatal Assertion 28578 2015-04-23T00:12:00.931-0400 I - [initandlisten]
2015-04-23T00:12:00.876-0400 I CONTROL ***** SERVER RESTARTED ***** 2015-04-23T00:12:00.931-0400 E NETWORK [initandlisten] 无法取消连接套接字文件 /tmp/mongodb -27017.sockerrno:1 不允许操作 2015-04-23T00:12:00.931-0400 I - [initandlisten] 致命断言 28578 2015-04-23T00:12:00.931-0400 I - [initandlisten]
回答by KurioZ7
I have fixed this issue myself, by deleting the mongodb-27017.sock
file . I ran the service after deleting this file, which worked fine. However, I am still not sure the root cause of the issue. The output of the command ls - lat /tmp/mongodb-27017.sock
is now
我已经通过删除mongodb-27017.sock
文件自己解决了这个问题。删除此文件后,我运行了该服务,效果很好。但是,我仍然不确定问题的根本原因。命令的输出ls - lat /tmp/mongodb-27017.sock
现在是
srwx------ 1 mongodb nogroup 0 Apr 23 06:24 /tmp/mongodb-27017.sock
回答by Bastronaut
Alternative to the answer provided by KurioZ7, you can simply set the permissions of the .sock file to the current user:
替代 KurioZ7 提供的答案,您可以简单地将 .sock 文件的权限设置为当前用户:
sudo chown `whoami` /tmp/mongodb-27017.sock
This does the trick for me if I want to run mongod without sudo. If I delete the file like in KurioZ7s answer, I will simply get the same error the next time I restart my machine.
如果我想在没有 sudo 的情况下运行 mongod,这对我有用。如果我像在 KurioZ7s 答案中那样删除文件,下次重新启动机器时我只会收到相同的错误。
回答by Greg Miller
This issue occurs when you use the command
使用命令时出现此问题
mongod
Before using the command
使用命令前
sudo service mongod start
To fix the issue, either:
要解决此问题,请执行以下任一操作:
Set appropriate permissions on the file:
对文件设置适当的权限:
/tmp/mongodb-27017.sock
OR
或者
Remove the file
删除文件
/tmp/mongodb-27017.sock
Run
跑
sudo service mongod start && mongod
回答by SpooForBrains
The most likely cause for this was that the mongod process was at some point started by the root user. The socket file (/tmp/mongodb-27017.sock) was therefore owned by the root user. The mongod process usually runs under its own dedicated user, and that user did not have the permissions to delete that file.
最可能的原因是 mongod 进程在某个时候由 root 用户启动。因此,套接字文件 (/tmp/mongodb-27017.sock) 归 root 用户所有。mongod 进程通常在其自己的专用用户下运行,该用户没有删除该文件的权限。
The solution, as you already found out, was to delete it. Then mongodb was able to recreate it with the correct permissions. This should persist after reboot, as long as mongodb is started using the init scripts, or under the correct user account.
正如您已经发现的,解决方案是删除它。然后 mongodb 能够使用正确的权限重新创建它。只要使用 init 脚本或在正确的用户帐户下启动 mongodb,这应该在重新启动后仍然存在。
回答by CodeBy
$ sudo mongod
it solve problem for me
它为我解决了问题
回答by Bafoo
For UNIX-based operating systems, as an alternative to the answer provided by Bastronaut, you could also specify the .sock file to be saved to a folder over which mongod has full user rights (corresponding to the way you are running mongod), that way mongod will also be able to remove the .sock file upon shutdown. The default folder to which the .sock file is saved is '/tmp'. To specify another folder, use a custom mongodb configuration file, for instance 'mongodb.conf', and add the following to it:
对于基于 UNIX 的操作系统,作为 Bastronaut 提供的答案的替代方案,您还可以指定要保存到 mongod 具有完全用户权限的文件夹中的 .sock 文件(对应于您运行 mongod 的方式),即mongod 也可以在关机时删除 .sock 文件。保存 .sock 文件的默认文件夹是“/tmp”。要指定另一个文件夹,请使用自定义 mongodb 配置文件,例如“mongodb.conf”,并向其中添加以下内容:
net:
unixDomainSocket:
pathPrefix: "anotherFolder"
After which you can run mongod with the command:
之后,您可以使用以下命令运行 mongod:
$ mongod --config /path/to/mongodb.conf
You can read the documentation on: https://docs.mongodb.org/manual/reference/configuration-options/#net.unixDomainSocket.pathPrefix
您可以阅读以下文档:https: //docs.mongodb.org/manual/reference/configuration-options/#net.unixDomainSocket.pathPrefix
回答by Rajith K
Change the ownership mongodb-27017.sock file in /tmp directory and start the mongod again.
更改 /tmp 目录中的所有权 mongodb-27017.sock 文件并再次启动 mongod。
cd /tmp
sudo chown mongodb:mongodb mongodb-27017.sock
sudo systemctl start mongod