设置 Mongodb 文件夹的读/写权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28987347/
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
Setting read/write permissions on Mongodb folder
提问by Zoltan King
I just finished installing MongoDB on OSX and setup a directory structure with sudo mkdir -p /data/db
.
我刚刚在 OSX 上安装完 MongoDB 并使用sudo mkdir -p /data/db
.
When I attempt to run mongod
from my user account it returns an error stating that my user account does not have read/write permission to /data/db
.
当我尝试mongod
从我的用户帐户运行时,它返回一个错误,指出我的用户帐户没有对/data/db
.
How can I set the proper read/write permissions on my account for /data/db
?
如何为我的帐户设置正确的读/写权限/data/db
?
回答by davidcondrey
Ensure that user account running mongod
has the proper directory permissions. You can check which permissions are set like so:
确保运行的用户帐户mongod
具有适当的目录权限。您可以像这样检查哪些权限设置:
ls -ld /data/db/
If they are set properly they should look something like this..
如果它们设置正确,它们应该看起来像这样..
drwxr-xr-x X user wheel XXX Date Time /data/db/
drwxr-xr-x X user wheel XXX Date Time /data/db/
If the permissions are set incorrectly you will likely see an error similar to this when attempting to run mongod
如果权限设置不正确,您可能会在尝试运行时看到与此类似的错误 mongod
exception in initAndListen: XXXXX Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
exception in initAndListen: XXXXX Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
To get the permissions set as they should be you can run the following command
要获得应有的权限设置,您可以运行以下命令
sudo chmod 0755 /data/db && sudo chown $USER /data/db
回答by getSantsoh
sudo chmod 777 /data/db/
Should work on Mac. Before running this cmd, permissions look like
应该在 Mac 上工作。在运行这个 cmd 之前,权限看起来像
drwxr-xr-x X User wheel Date /data/db
after running the cmd
运行cmd后
drwxrwxrwx X User wheel Date /data/db
回答by Tim Anishere
This is what worked for me. I am using a Mac, although you could try if you're using windows.
这对我有用。我使用的是 Mac,不过如果您使用的是 Windows,您可以尝试一下。
sudo chmod 777 /data/db
回答by aaron
There are three categories of users: owners, those in the group, and everyone else; chmod 777 /path/to/file
lets everyone read/write the file, but chmod 775 /path/to/file
lets only the owner/group read/write the file. Definitely use chmod 775 /path/to/file
if you're developing a web server.
用户分为三类:所有者、组内用户和其他所有人;chmod 777 /path/to/file
允许每个人读/写文件,但chmod 775 /path/to/file
只允许所有者/组读/写文件。chmod 775 /path/to/file
如果您正在开发 Web 服务器,请务必使用。
Some useful reading, especially for reasoning behind why 777, 775, and so on are used rather than other numbers: https://www.maketecheasier.com/file-permissions-what-does-chmod-777-means/
一些有用的阅读,特别是用于解释为什么使用 777、775 等而不是其他数字的原因:https: //www.maketecheasier.com/file-permissions-what-does-chmod-777-means/
回答by b__
None of these suggestions are correct, there's something else wrong with mongodb-org-3.4.16-1.el7.x86_64. It cannot start with a custom db path.
这些建议都不正确,mongodb-org-3.4.16-1.el7.x86_64 还有其他问题。它不能以自定义数据库路径开头。
[root@localhost vagrant]# chmod 777 /data/ /data/mongodb
[root@localhost vagrant]# chown mongod:mongod /data/ /data/mongodb
[root@localhost vagrant]# ls -lad /data/mongodb/
drwxrwxrwx. 2 mongod mongod 6 Jul 11 15:24 /data/mongodb/
[root@localhost vagrant]# systemctl start mongod
Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
[root@localhost vagrant]# stat /data/mongodb^C
[root@localhost vagrant]# !tail
tail /var/log/mongodb/mongod.log
2018-07-11T15:39:10.786+0000 I STORAGE [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/mongodb, terminating
2018-07-11T15:39:10.786+0000 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2018-07-11T15:39:10.786+0000 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2018-07-11T15:39:10.786+0000 I CONTROL [initandlisten] now exiting
2018-07-11T15:39:10.786+0000 I CONTROL [initandlisten] shutting down with code:100
[root@localhost vagrant]# rpm -qa | grep mongo
mongodb-org-tools-3.4.16-1.el7.x86_64
mongodb-org-shell-3.4.16-1.el7.x86_64
mongodb-org-server-3.4.16-1.el7.x86_64
mongodb-org-mongos-3.4.16-1.el7.x86_64
mongodb-org-3.4.16-1.el7.x86_64
回答by suzmas
None of the given answers were working for me. I ended up configuring my personal OS user to be the root user, then manually went to the db folder - right clicked to view info - and added myself with read and write permissions.
没有一个给定的答案对我有用。我最终将我的个人操作系统用户配置为 root 用户,然后手动转到 db 文件夹 - 右键单击以查看信息 - 并为自己添加了读写权限。
回答by Artem
Just run
赶紧跑
sudo chown group:user /data/db
where group
is a group of your user
group
你的用户组在哪里