无法在本地计算机上运行mongodb 4.0版

时间:2018-07-24 05:15:45

标签: mongodb

当我尝试运行命令mongo时出现此错误:

MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
2018-07-24T13:08:13.968+0800 E QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:251:13
@(connect):1:6
exception: connect failed

运行此命令sudo service mongod status后,它会向我输出如下内容:

mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: core-dump) since Sel 2018-07-24 13:18:18 +08; 45s ago
Docs: https://docs.mongodb.org/manual
Process: 18153 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=dumped, signal=ABRT)
Main PID: 18153 (code=dumped, signal=ABRT)
root@him: systemd[1]: Started MongoDB Database Server.
root@him: mongod[18153]: 2018-07-24T13:18:18.777+0800 I CONTROL  [main] Automatically disabling TLS 1.0, to f
root@him: mongod.service: Main process exited, code=dumped, status=6/ABRT
root@him: mongod.service: Unit entered failed state.
root@him: mongod.service: Failed with result 'core-dump'.

2 个答案:

答案 0 :(得分:0)

从终端运行时,数据文件是在root而不是mongodb用户下创建的。

您需要授予权限:

cd /var/lib/mongodb
sudo chown -R mongodb:mongodb *

希望这会有所帮助。

答案 1 :(得分:0)

我遇到了同样的错误,可能是因为 ubuntu 从 18.04 升级到 20.04。无法手动启动 mongod,原因是没有 /data/db 及其权限。然后 mongod 将手动启动,但在 mongodb.service 上仍然出错。最后重新安装 mongodb 工作。这是一个新安装,所以不关心备份。

$ sudo apt remove mongodb mongo-tools mongodb-clients mongodb-server mongodb-server-core
$ sudo apt autoremove
$ sudo rm -rf /var/lib/mongodb/
$ sudo apt install mongodb