总结:MongoDB 抱怨目录上的权限问题,其中所有内容都是允许的。
我正在运行MongoDB v2.4.10
。Debian Jessie ARM
我想将数据存储在外部驱动器上,该驱动器已格式化并通过以下行ext4
安装:/etc/fstab
UUID=<uuid goes here> /mnt/external1 ext4 defaults,noatime 0 0
的权限/mnt/external1
为:
$ ls -l | grep external1
drwxrwxrwx 4 root plugdev 4096 Jul 31 10:57 external1
它们是在驱动器安装后通过发出以下命令设置的:
$ sudo chown -R root:plugdev /mnt/external1
$ sudo chmod 777 -R /mnt/external1
该mongodb
用户属于以下组plugdev
:
$ cat /etc/group | grep mongodb
plugdev:x:46:mongodb
mongodb:x:112:mongodb
但是,运行后sudo service mongodb start
我看到以下内容/mnt/external1/mongodb.log
:
Fri Jul 31 10:56:17.341 [initandlisten] MongoDB starting : pid=27189 port=27017 dbpath=/mnt/external1/mongodb 32-bit host=odroidc1
Fri Jul 31 10:56:17.341 [initandlisten]
Fri Jul 31 10:56:17.341 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
Fri Jul 31 10:56:17.341 [initandlisten] ** 32 bit builds are limited to less than 2GB of data (or less with --journal).
Fri Jul 31 10:56:17.341 [initandlisten] ** See http://dochub.mongodb.org/core/32bit
Fri Jul 31 10:56:17.343 [initandlisten]
Fri Jul 31 10:56:17.343 [initandlisten] db version v2.4.10
Fri Jul 31 10:56:17.343 [initandlisten] git version: nogitversion
Fri Jul 31 10:56:17.343 [initandlisten] build info: Linux hartmann 3.16.0-0.bpo.4-armmp-lpae #1 SMP Debian 3.16.7-ckt4-3~bpo70+1 (2015-02-12) armv7l BOOST_LIB_VERSION=1_55
Fri Jul 31 10:56:17.343 [initandlisten] allocator: system
Fri Jul 31 10:56:17.343 [initandlisten] options: { bind_ip: "<ip goes here>", config: "/etc/mongodb.conf", dbpath: "/mnt/external1/mongodb", journal: "true", logappend: "true", logpath: "/mnt/external1/mongodb.log" }
Fri Jul 31 10:56:18.002 [initandlisten] journal dir=/mnt/external1/mongodb/journal
Fri Jul 31 10:56:18.002 [initandlisten] recover : no journal files present, no recovery needed
Fri Jul 31 10:56:18.003 [initandlisten] warning couldn't write to / rename file /mnt/external1/mongodb/journal/prealloc.0: couldn't open file /mnt/external1/mongodb/journal/prealloc.0 for writing errno:1 Operation not permitted
Fri Jul 31 10:56:18.022 [initandlisten] couldn't open /mnt/external1/mongodb/local.ns errno:1 Operation not permitted
Fri Jul 31 10:56:18.022 [initandlisten] error couldn't open file /mnt/external1/mongodb/local.ns terminating
Fri Jul 31 10:56:18.022 dbexit:
Fri Jul 31 10:56:18.022 [initandlisten] shutdown: going to close listening sockets...
Fri Jul 31 10:56:18.023 [initandlisten] shutdown: going to flush diaglog...
Fri Jul 31 10:56:18.023 [initandlisten] shutdown: going to close sockets...
Fri Jul 31 10:56:18.023 [initandlisten] shutdown: waiting for fs preallocator...
Fri Jul 31 10:56:18.023 [initandlisten] shutdown: lock for final commit...
Fri Jul 31 10:56:18.023 [initandlisten] shutdown: final commit...
Fri Jul 31 10:56:18.023 [initandlisten] shutdown: closing all files...
Fri Jul 31 10:56:18.023 [initandlisten] closeAllFiles() finished
Fri Jul 31 10:56:18.023 [initandlisten] journalCleanup...
Fri Jul 31 10:56:18.023 [initandlisten] removeJournalFiles
Fri Jul 31 10:56:18.027 [initandlisten] shutdown: removing fs lock...
Fri Jul 31 10:56:18.028 dbexit: really exiting now
这意味着MongoDB
可以附加到现有文件(日志本身),但不能创建新文件。
root:plugdev
如果我将所有者设置为而不是(我认为这是安装外部驱动器的标准方法;如果我错了,请纠正我) mongodb:mongodb
,问题就会消失。但是,我希望正确设置,而不是通过黑客手段。
我怎样才能做到这一点?
答案1
将 的所有者设置/mnt/external1/mongodb
为/mnt/external1/mongodb.log
即可mongodb:mongodb
解决问题。但是,如果驱动器格式化为 NTFS 并通过 挂载ntfs-3g
,则此解决方案将不起作用,除非将整个驱动器的所有者设置为mongodb:mongodb
。我将问题标记为已解决,因为从形式上看,这确实是我遇到的问题的解决方案。