错误信息如下:
2018-07-06T23:28:54.978+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2018-07-06T23:28:55.092+0800 I CONTROL [initandlisten] MongoDB starting : pid=14447 port=27017 dbpath=/data/db 64-bit host=wangmengxideMacBook-Pro.local
2018-07-06T23:28:55.092+0800 I CONTROL [initandlisten] db version v4.0.0
2018-07-06T23:28:55.092+0800 I CONTROL [initandlisten] git version: 3b07af3d4f471ae89e8186d33bbb1d5259597d51
2018-07-06T23:28:55.092+0800 I CONTROL [initandlisten] allocator: system
2018-07-06T23:28:55.092+0800 I CONTROL [initandlisten] modules: none
2018-07-06T23:28:55.092+0800 I CONTROL [initandlisten] build environment:
2018-07-06T23:28:55.092+0800 I CONTROL [initandlisten] distarch: x86_64
2018-07-06T23:28:55.092+0800 I CONTROL [initandlisten] target_arch: x86_64
2018-07-06T23:28:55.092+0800 I CONTROL [initandlisten] options: {}
2018-07-06T23:28:55.107+0800 I STORAGE [initandlisten] exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, terminating
2018-07-06T23:28:55.115+0800 I CONTROL [initandlisten] now exiting
2018-07-06T23:28:55.115+0800 I CONTROL [initandlisten] shutting down with code:100
原因是:
对于文件夹 /data/db 没有操作权限,目前这个文件夹只有只读权限
解决办法
确保/data/db目录在bin文件夹下,如果不在的话,可以cd到bin文件夹,再修改文件夹权限
bin xxx$ sudo chomd -R /data/db