0

我正在尝试在 ubuntu 16.10 上安装 mongodb,尽管它没有在支持的版本中列出。我首先在尝试启动 mongo shell 时遇到此错误:

MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
2018-07-12T11:15:00.464+0200 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 start但我得到了Unit mongod.service not found. 我也尝试修改 mongodb.service 文件,检查锁定文件,运行修复命令并重新安装 mongo。

在 中的指定位置找不到日志文件mongod.conf,在 中没有mongodb目录/var/log

4

1 回答 1

1

您需要在 systemd 中创建 mongodb 服务。

sudo vim /etc/systemd/system/mongodb.service

内容:

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
LimitFSIZE=infinity
LimitCPU=infinity
LimitAS=infinity
LimitNOFILE=64000
LimitNPROC=64000
User=mongodb
ExecStart=/usr/bin/mongod --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target

启动时自动启动:

sudo systemctl enable mongodb

开始/停止/状态:

sudo systemctl start/stop/status mongodb
sudo service mongodb start/stop/status
于 2018-07-12T09:56:18.480 回答