开启MongoDB服务报错

2017-11-30  本文已影响30人  BlueEagleBoy

1.下载安装好mongoDB之后 我们要在终端开启mongo的服务 命令如下:

mongod

*mongod 为开启mongo的服务

错误1:

1.执行之后报错

2017-11-30T15:50:26.673+0800 I CONTROL  [initandlisten] MongoDB starting : pid=39872 port=27017 dbpath=/data/db 64-bit host=localhost
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten] db version v3.4.10
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten] git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2m  2 Nov 2017
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten] allocator: system
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten] modules: none
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten] build environment:
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten]     distarch: x86_64
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2017-11-30T15:50:26.675+0800 I CONTROL  [initandlisten] options: {}
2017-11-30T15:50:26.677+0800 I STORAGE  [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating
2017-11-30T15:50:26.677+0800 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2017-11-30T15:50:26.677+0800 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2017-11-30T15:50:26.678+0800 I CONTROL  [initandlisten] now exiting
2017-11-30T15:50:26.678+0800 I CONTROL  [initandlisten] shutting down with code:100

可以看里面有个提示信息:

2017-11-30T15:50:26.677+0800 I STORAGE  [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating

这是缺失/db文件目录 解决方法在终端输入如下命令创建目录:

 sudo mkdir -p /data/db

错误2:

然后继续执行gongod命令 发现报错如下:

localhost:~ mengwang$ mongod
2017-11-30T15:50:26.673+0800 I CONTROL  [initandlisten] MongoDB starting : pid=39872 port=27017 dbpath=/data/db 64-bit host=localhost
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten] db version v3.4.10
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten] git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2m  2 Nov 2017
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten] allocator: system
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten] modules: none
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten] build environment:
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten]     distarch: x86_64
2017-11-30T15:50:26.674+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2017-11-30T15:50:26.675+0800 I CONTROL  [initandlisten] options: {}
2017-11-30T15:50:26.677+0800 I STORAGE  [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating
2017-11-30T15:50:26.677+0800 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2017-11-30T15:50:26.677+0800 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2017-11-30T15:50:26.678+0800 I CONTROL  [initandlisten] now exiting
2017-11-30T15:50:26.678+0800 I CONTROL  [initandlisten] shutting down with code:100

可以看里面有个提示信息:

2017-11-30T15:50:26.677+0800 I STORAGE  [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating

这是由于刚刚创建的目录没有读写权限,输入命令设置读写权限:

sudo chmod -R go+w /data/db

然后在执行mongod命令 服务就启动成功了。
可以在浏览器输入http://localhost:27017测试一下 会在网页输出

It looks like you are trying to access MongoDB over HTTP on the native driver port

安装MongoDB可以参考:http://www.jianshu.com/p/2d0a1ecd0c82

上一篇下一篇

猜你喜欢

热点阅读