Mongo 对执行用户拥有的目录的只读权限失败

Mongo fails on read-only permissions for a directory owned by the executing user

我 运行 正在 Ubuntu 18.04 作为普通 sudo-er 用户:

test:~$ whoami
mugen

并且我家有一个db目录(省略无关文件):

test:~$ ls -la /home/mugen
total 64
drwxr-xr-x  7 mugen mugen 4096 Mar 17 14:08 .
drwxr-xr-x 13 root  root  4096 Mar 17 13:32 ..
-rw-------  1 root  root  1778 Mar 17 14:07 .bash_history
-rw-r--r--  1 mugen mugen  220 Apr  4  2018 .bash_logout
-rw-r--r--  1 mugen mugen 3771 Apr  4  2018 .bashrc
drwx------  2 mugen mugen 4096 Feb 25 08:20 .cache
drwxr-xr-x  3 root  root  4096 Mar 17 13:43 .config
drwxrwxr-x  4 mugen mugen 4096 Mar 17 14:09 db

我正在尝试 运行 mongo 使用:mongod --dbpath /home/mugen/db

但它在以下方面失败了:

2020-03-17T14:10:10.735+0000 I  CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-03-17T14:10:10.738+0000 I  CONTROL  [initandlisten] MongoDB starting : pid=14315 port=27017 dbpath=/home/mugen/db 64-bit host=test
2020-03-17T14:10:10.738+0000 I  CONTROL  [initandlisten] db version v4.2.3
2020-03-17T14:10:10.738+0000 I  CONTROL  [initandlisten] git version: 6874650b362138df74be53d366bbefc321ea32d4
2020-03-17T14:10:10.738+0000 I  CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.1.1  11 Sep 2018
2020-03-17T14:10:10.738+0000 I  CONTROL  [initandlisten] allocator: tcmalloc
2020-03-17T14:10:10.738+0000 I  CONTROL  [initandlisten] modules: none
2020-03-17T14:10:10.738+0000 I  CONTROL  [initandlisten] build environment:
2020-03-17T14:10:10.738+0000 I  CONTROL  [initandlisten]     distmod: ubuntu1804
2020-03-17T14:10:10.738+0000 I  CONTROL  [initandlisten]     distarch: x86_64
2020-03-17T14:10:10.738+0000 I  CONTROL  [initandlisten]     target_arch: x86_64
2020-03-17T14:10:10.738+0000 I  CONTROL  [initandlisten] options: { storage: { dbPath: "/home/mugen/db" } }
2020-03-17T14:10:10.739+0000 I  STORAGE  [initandlisten] exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /home/mugen/db, terminating
2020-03-17T14:10:10.739+0000 I  NETWORK  [initandlisten] shutdown: going to close listening sockets...
2020-03-17T14:10:10.739+0000 I  -        [initandlisten] Stopping further Flow Control ticket acquisitions.
2020-03-17T14:10:10.739+0000 I  CONTROL  [initandlisten] now exiting
2020-03-17T14:10:10.739+0000 I  CONTROL  [initandlisten] shutting down with code:100

如果我对目录添加"others"写权限,它就可以正常工作。但我不想。 mongod 运行 不是执行用户吗?我可以不同地配置它吗?

Troubleshooting - The data directory must be accessible

The data directory must be configured with the appropriate permissions and ownership settings to allow the mongod to read, write, and navigate the directory contents (rwx user or group permissions).

您必须允许用户 mongod 写入此文件夹。或者您可以将用户 mongod 添加到组 mugen 例如。