个人最近正在研究mongo DB,是通过brew install mongodb安装的。
然后通过
db.shutdownServer();
停止了服务。
然后在运行mongod就报错了。
superpeng@bogon ~ mongod
2018-06-13T16:38:25.137+0800 I CONTROL [initandlisten] MongoDB starting : pid=15496 port=27017 dbpath=/data/db 64-bit host=bogon
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] db version v3.6.5
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] git version: a20ecd3e3a174162052ff99913bc2ca9a839d618
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2o 27 Mar 2018
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] allocator: system
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] modules: none
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] build environment:
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] distarch: x86_64
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] target_arch: x86_64
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] options: {}
2018-06-13T16:38:25.138+0800 I STORAGE [initandlisten] exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, terminating
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] now exiting
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] shutting down with code:100
报错中说到,是不能读取/data/db,我们先添加这个文件夹
sudo mkdir -p /data/db
然后我们再尝试开启mongodb
mongodb
superpeng@bogon ~ mongod
2018-06-13T16:38:25.137+0800 I CONTROL [initandlisten] MongoDB starting : pid=15496 port=27017 dbpath=/data/db 64-bit host=bogon
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] db version v3.6.5
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] git version: a20ecd3e3a174162052ff99913bc2ca9a839d618
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2o 27 Mar 2018
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] allocator: system
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] modules: none
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] build environment:
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] distarch: x86_64
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] target_arch: x86_64
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] options: {}
2018-06-13T16:38:25.138+0800 I STORAGE [initandlisten] exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, terminating
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] now exiting
2018-06-13T16:38:25.138+0800 I CONTROL [initandlisten] shutting down with code:100
还是报错了,我们来查看下权限
cd /data/db
ls -l => 查看文件夹权限
-rw------- 1 root wheel 48 6 5 16:17 WiredTiger
-rw------- 1 root wheel 21 6 5 16:17 WiredTiger.lock
-rw------- 1 root wheel 1043 6 5 16:19 WiredTiger.turtle
-rw------- 1 root wheel 53248 6 5 16:19 WiredTiger.wt
-rw------- 1 root wheel 4096 6 5 16:19 WiredTigerLAS.wt
-rw------- 1 root wheel 16384 6 5 16:19 _mdb_catalog.wt
-rw------- 1 root wheel 16384 6 5 16:19 collection-0-2425423596569211332.wt
-rw------- 1 root wheel 32768 6 5 16:19 collection-2-2425423596569211332.wt
drwx------ 4 root wheel 128 6 5 16:19 diagnostic.data
-rw------- 1 root wheel 16384 6 5 16:19 index-1-2425423596569211332.wt
-rw------- 1 root wheel 32768 6 5 16:19 index-3-2425423596569211332.wt
drwx------ 5 root wheel 160 6 5 16:18 journal
-rw------- 1 root wheel 0 6 5 16:19 mongod.lock
-rw------- 1 root wheel 32768 6 5 16:19 sizeStorer.wt
-rw------- 1 root wheel 114 6 5 16:17 storage.bson
发现权限都是root的,让它的父级有最高(本机名字,我的是superpeng)权限吧
sudo chown -R superpeng /data
然后再连接mongodb就可以了
mongod