我尝试在 Ubuntu 16.04 服务器上运行 v2.6.10:
sudo service mongod start
并得到结果:
mongod start/running, process 67725
但当我检查状态时,我得到了:
mongod stop/waiting
日志内容:
2017-09-10T07:47:16.528+0200 [initandlisten] MongoDB starting : pid=5493 port=27017 dbpath=/data/db 64-bit host=ns1
2017-09-10T07:47:16.529+0200 [initandlisten] db version v2.6.10
2017-09-10T07:47:16.529+0200 [initandlisten] git version: nogitversion
2017-09-10T07:47:16.529+0200 [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2017-09-10T07:47:16.529+0200 [initandlisten] build info: Linux lgw01-12 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 BOOST_LIB_VERSION=1_58
2017-09-10T07:47:16.529+0200 [initandlisten] allocator: tcmalloc
2017-09-10T07:47:16.529+0200 [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/data/db", journal: { enable$
2017-09-10T07:47:16.529+0200 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod ins$
2017-09-10T07:47:16.529+0200 [initandlisten] dbexit:
2017-09-10T07:47:16.529+0200 [initandlisten] shutdown: going to close listening sockets...
2017-09-10T07:47:16.529+0200 [initandlisten] shutdown: going to flush diaglog...
2017-09-10T07:47:16.529+0200 [initandlisten] shutdown: going to close sockets...
2017-09-10T07:47:16.529+0200 [initandlisten] shutdown: waiting for fs preallocator...
2017-09-10T07:47:16.529+0200 [initandlisten] shutdown: lock for final commit...
2017-09-10T07:47:16.529+0200 [initandlisten] shutdown: final commit...
2017-09-10T07:47:16.529+0200 [initandlisten] shutdown: closing all files...
2017-09-10T07:47:16.529+0200 [initandlisten] closeAllFiles() finished
2017-09-10T07:47:16.529+0200 [initandlisten] shutdown: removing fs lock...
2017-09-10T07:47:16.530+0200 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
2017-09-10T07:47:16.530+0200 [initandlisten] dbexit: really exiting now
答案1
根据该日志行,这是一个权限问题。
/data/db/mongod.lock errno:13 权限被拒绝 是 mongod ins$ 2017-09-10T07:47:16.529+0200 [initandlisten] dbexit:
看来您已将dbpath
默认设置更改/var/lib/mongodb
为/etc/mongodb.conf
修复 上的权限和所有权/data/db
。假设您使用了包用户:组应该mongodb:mongodb因此以下命令应该可以让它在这个自定义位置工作。
更改权限以镜像包位置:
sudo chmod 755 /data/db
确保目录所有权与官方包相同:
sudo chown mongodb:mongodb /data/db