MongoDB - 套接字权限被拒绝:/tmp/mongodb-27017.sock

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8479384/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 12:22:03  来源:igfitidea点击:

MongoDB - Permission denied for socket: /tmp/mongodb-27017.sock

socketsmongodbfile-permissionsupstart

提问by user837208

I had an unclean shutdown of MongoDB on Ubuntu 10.04 LTS. Now when I login as root and run Mongodb via service mongodb start, I get below error-

我在 Ubuntu 10.04 LTS 上不正常关闭了 MongoDB。现在,当我以 root 身份登录并通过 service mongodb start 运行 Mongodb 时,出现以下错误-

Mon Dec 12 13:53:15 [initandlisten] ERROR: listen(): bind() failed errno:13 Permission denied for socket: /tmp/mongodb-27017.sock

When I run MongoDB manually via root, it works just fine.

当我通过 root 手动运行 MongoDB 时,它工作得很好。

I can confirm that there is no /tmp/mongodb-27017.sock file

我可以确认没有 /tmp/mongodb-27017.sock 文件

root@devbox:~# ll /tmp/
total 16
drwxr-xr-x  4 root root 4096 2011-12-12 13:53 ./
drwxr-xr-x 25 root root 4096 2011-12-11 13:06 ../
drwxrwxrwt  2 root root 4096 2011-12-12 13:01 .ICE-unix/
drwxrwxrwt  2 root root 4096 2011-12-12 13:01 .X11-unix/

Where do I begin troubleshooting?

我从哪里开始故障排除?

采纳答案by Dr Joe

What's are the file permissions on /tmp? Is it possible that they've been changed?

/tmp 上的文件权限是什么?有没有可能他们已经改变了?

A

一种

# ls -ld /tmp

will tell you.

会告诉你。

If you're unsure try:

如果您不确定,请尝试:

# chown root:root /tmp
# chmod 1777 /tmp

That might fix it.

那可能会解决它。

回答by Adil Abbasi

Try changing owner like this,

尝试像这样改变所有者,

sudo chown mongodb:mongodb /tmp/mongodb-27017.sock

回答by Chu-Siang Lai

I have same issue, because I have use run mongodb by root, it will start fail with systemctlon CentOS 7.3.

我有同样的问题,因为我使用 root 运行 mongodb,它会systemctl在 CentOS 7.3 上启动失败。

Please use the correct permission for mongodb. $ sudo chown -R mongod:mongod \ /var/run/mongodb/mongod.pid \ /tmp/mongodb-27017.sock \ /var/lib/mongo/

请为 mongodb 使用正确的权限。 $ sudo chown -R mongod:mongod \ /var/run/mongodb/mongod.pid \ /tmp/mongodb-27017.sock \ /var/lib/mongo/

If we have other fail like Error reading file /path/file: Permission denied, maybe we can fix it by SELinux. $ sudo chcon -v -t mongod_var_lib_t /path/file

如果我们有其他失败Error reading file /path/file: Permission denied,也许我们可以通过SELinux修复它。 $ sudo chcon -v -t mongod_var_lib_t /path/file

By the way, I don't recomment use the 777 permission, it's so danger. :P

顺便说一句,我不建议使用777权限,它太危险了。:P

回答by mature

In the Versions before 3.0 the socket was created with 777 permissions by default. Most the most correct way set permissions to mongod socket is set value in mongodb.conf. For example:

在 3.0 之前的版本中,默认情况下创建的套接字具有 777 权限。为 mongod 套接字设置权限最正确的方法是在mongodb.conf 中设置值。例如:

sudo vim /usr/local/etc/mongodb.conf

and insert line:

并插入行:

filePermissions = 0777 

to it.

到它。

In case if you will try directly change permissions to /tmp/mongodb-27017.sockwith chownand chmodyou can have a chance set it temporary. And have a old permissions after mongod service restart or server reboot.

如果您尝试使用chownchmod直接更改对/tmp/mongodb-27017.sock权限,您可以将其设置为临时。并在 mongod 服务重启或服务器重启后拥有旧权限。

回答by dream-blue

we use mac and install mongodb, usually do not need mongodb.conf, so, try this:

我们使用mac并安装mongodb,通常不需要mongodb.conf,所以,试试这个:

sudo chown -R your-username /tmp/

ps:your-username is your username in mac os, not root.if you don't know what is your username,there's a command:

ps:your-username 是你在 mac os 中的用户名,不是 root。如果你不知道你的用户名是什么,有一个命令:

whoami

回答by Travis

Make sure the Ubuntu mongo user has access to the file. The Mongo Ubuntu service uses the Ubuntu Mongo user. To find out the mongo username is go to /var/lib/mongodb directory and show the permissions: ls -l

确保 Ubuntu mongo 用户有权访问该文件。Mongo Ubuntu 服务使用 Ubuntu Mongo 用户。要找出 mongo 用户名,请转到 /var/lib/mongodb 目录并显示权限: ls -l