当我尝试使用启动 MongoDB 时mongod
,它返回以下消息:
2017-03-09T20:54:48.868-0300 I CONTROL [initandlisten] MongoDB starting : pid=9556 port=27017 dbpath=/data/db 64-bit host=kallel-Aspire-ES1-511
2017-03-09T20:54:48.868-0300 I CONTROL [initandlisten] db version v3.4.2
2017-03-09T20:54:48.869-0300 I CONTROL [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2017-03-09T20:54:48.869-0300 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2017-03-09T20:54:48.869-0300 I CONTROL [initandlisten] allocator: tcmalloc
2017-03-09T20:54:48.869-0300 I CONTROL [initandlisten] modules: none
2017-03-09T20:54:48.869-0300 I CONTROL [initandlisten] build environment:
2017-03-09T20:54:48.869-0300 I CONTROL [initandlisten] distmod: ubuntu1604
2017-03-09T20:54:48.869-0300 I CONTROL [initandlisten] distarch: x86_64
2017-03-09T20:54:48.869-0300 I CONTROL [initandlisten] target_arch: x86_64
2017-03-09T20:54:48.869-0300 I CONTROL [initandlisten] options: {}
2017-03-09T20:54:48.869-0300 I STORAGE [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating
2017-03-09T20:54:48.869-0300 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-03-09T20:54:48.869-0300 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-03-09T20:54:48.869-0300 I CONTROL [initandlisten] now exiting
2017-03-09T20:54:48.869-0300 I CONTROL [initandlisten] shutting down with code:100
我该如何解决呢,我不想每次都执行 sudo 操作。
答案1
您应该使用 root 或 sudo 启动服务 (mongod)。例如:
sudo service mongod start
但是,无需 root 权限,使用 mongo 客户端进行连接
mongo