我以普通sudo er用户身份在Ubuntu 18.04上运行:
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
我正在尝试使用:mongod --dbpath /home/mugen/db
运行mongo
但它在以下方面失败了:
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
如果我将"其他"写入权限添加到目录中,效果会很好。但我不想。mongod
不是作为执行用户运行的吗?我可以以不同的方式配置它吗?
请参阅故障排除-数据目录必须可访问
数据目录必须配置适当的权限和所有权设置,以允许mongod读取、写入和导航目录内容(rwx用户或组权限(。
您必须允许用户mongod
写入此文件夹。例如,您也可以将用户mongod
添加到组mugen
中。