mac mongoDB终止服务后再重启报错完美解决。

个人最近正在研究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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Mac MongoDB安装 一、安装 MongoDB的安装方法有很多,本文以官方文档中的两种方法为准。 1. 手动...
    Keriy阅读 16,760评论 2 7
  • 1.提取图片 [D 160418 15:31:06 connectionpool:383] "POST /math...
    潇湘阳阳阅读 854评论 2 0
  • bg,略延续养成篇的情节 优考上东大那天,s君深深体会到了吾家有女初长成的骄傲感。 简直恨不得召开个新闻发布会让世...
    十一的影子阅读 470评论 0 0
  • 学习要点:人生要时时“有意注意”。 学习感悟:仔细观察很重要,时刻有意注意,就会成功。 1、付出不亚于任何人的努力...
    梦琳_4444阅读 202评论 0 0
  • 写个代码试试 ``` Class LSApplicationWorkspace_class =objc_getCl...
    doudou2阅读 273评论 0 0