mongodb 数据目录权限

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

mongodb data directory permissions

mongodb

提问by Mark Gill

Earlier i was storing all the mongodb data files in /var/lib/mongodb directory..and the dbpath entry in /etc/mongodb.conf was /var/lib/mongodb..

早些时候,我将所有 mongodb 数据文件存储在 /var/lib/mongodb 目录中..而 /etc/mongodb.conf 中的 dbpath 条目是 /var/lib/mongodb..

Now i want to change the data directory to /vol/db..so I created the directory /vol/db and changed the permissions using sudo chown -R id -u/vol/db and changed the db path entry to /vol/db in /etc/mongodb.conf

现在我想将数据目录更改为 /vol/db..so 我创建了目录 /vol/db 并使用 sudo chown -R id -u/vol/db更改了权限,并将 db 路径条目更改为 /vol/db in /等/mongodb.conf

now when i start the mongodb using sudo service mongodb start..i am getting this error in /var/log/mongodb/mongodb.log

现在,当我使用 sudo service mongodb start 启动 mongodb 时..我在 /var/log/mongodb/mongodb.log 中收到此错误

http://pastebin.com/C0tv8HQN

http://pastebin.com/C0tv8HQN

i need help..where I am wrong?

我需要帮助..我错在哪里?

回答by kaezarrex

I was having the same problem, but was able to solve it thanks to a similar question. You need to make sure that /vol/db/is owned by mongodb.

我遇到了同样的问题,但由于一个类似的问题,我能够解决它。您需要确保它/vol/db/mongodb.

sudo chown -R mongodb:mongodb /vol/db/

If you get the error chown: invalid user: 'mongodb:mongodb', check /etc/passwdto see if there is a similar user that exists (ex. mongod).

如果出现错误chown: invalid user: 'mongodb:mongodb',请检查/etc/passwd是否存在类似的用户(例如mongod)。

回答by Federico Giust

The easiest would be

最简单的是

sudo chmod 777 /data/db

回答by drpoo

If after changing permissions and ownership of the new db path, you're still seeing this issue, run getenforceto see if you are using a system with SELinux running in enforce mode. If getenforce returns 'enforcing', it's likely selinux is the cause of the permissions error, since mongodb is now running outside it's original context scope since the db location changed out of /var/lib/...

如果在更改新 db 路径的权限和所有权后,您仍然看到此问题,请运行getenforce以查看您是否正在使用以强制模式运行 SELinux 的系统。如果 getenforce 返回 'enforcing',则很可能 selinux 是权限错误的原因,因为 mongodb 现在在其原始上下文范围之外运行,因为 db 位置已从 /var/lib/...

I don't know the details, but a brute force way then to resolve the issue without writing your own selinux policy for the new context is to simply turn off selinux :-/

我不知道细节,但是在不为新上下文编写自己的 selinux 策略的情况下解决问题的蛮力方法是简单地关闭 selinux :-/

sudo setenforce 0

Ideally, you'd figure out how to update the selinux policy if you're planning to run in production.

理想情况下,如果您计划在生产中运行,您应该弄清楚如何更新 selinux 策略。

回答by M0hsen

I suggest to check what is the error by reading mongo log

我建议通过阅读 mongo 日志来检查错误是什么

tail -50 /var/log/mongodb/mongodb.log

you can immediately find the problem(including permission ones)

您可以立即找到问题(包括许可问题)

回答by Vinicius Santana

Try the following:

请尝试以下操作:

$ sudo chmod 755 /vol/db && sudo chown $USER /vol/db