Mongodb:Active:失败(结果:退出代码)

6
> mongod.service - MongoDB Database Server
>      Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
>      Active: failed (Result: exit-code) since Tue 2020-09-08 02:53:14 IST; 7min ago
>        Docs: https://docs.mongodb.org/manual    Main PID: 6128 (code=exited, status=2)
> 
> Sep 08 02:53:14 saket-HP-ProBook-440-G4 systemd[1]: Started MongoDB
> Database Server. Sep 08 02:53:14 saket-HP-ProBook-440-G4 mongod[6128]:
> Error parsing YAML config file: yaml-cpp: error at line 24, column 3:
> end of map not fo> Sep 08 02:53:14 saket-HP-ProBook-440-G4
> mongod[6128]: try '/usr/bin/mongod --help' for more information Sep 08
> 02:53:14 saket-HP-ProBook-440-G4 systemd[1]: mongod.service: Main
> process exited, code=exited, status=2/INVALIDARGUMENT Sep 08 02:53:14
> saket-HP-ProBook-440-G4 systemd[1]: mongod.service: Failed with result
> 'exit-code'. Sep 08 02:58:34 saket-HP-ProBook-440-G4 systemd[1]:
> /lib/systemd/system/mongod.service:11: PIDFile= references a path
> below legacy directory > Sep 08 03:00:52 saket-HP-ProBook-440-G4
> systemd[1]: /lib/systemd/system/mongod.service:11: PIDFile= references
> a path below legacy directory > lines 1-13/13 (END)

我已经尝试了所有可用的解决方案,但很不幸它们对我都不起作用。我正在使用Ubuntu 20.04


1
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/#install-mongodb-community-edition-on-ubuntu - Joe
请按照@joe提供的链接中的说明进行操作,即可安装/升级MongoDB版本至4.4。 - vshenoy
3个回答

5

只需在Ubuntu 20.04中运行以下命令:

sudo systemctl start mongod

然后运行:

mongod --fork --logpath /var/log/mongodb/mongodb.log --auth --port 27017 --dbpath /var/lib/mongodb

然后运行:

mongo

对我而言,它起作用了。


1
这对我没有起作用。我收到了错误消息 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 : - Rylan Schaeffer

1
请确保您已输入以下命令: sudo systemctl start mongodb 因为我在没有启动mongodb启动脚本的情况下检查了状态。

0

我在Ubuntu 21.10上安装MongoDB时遇到了问题,按照官方文档中的步骤操作后,出现了与原帖作者相同的错误。以下步骤适用于我(需要重新启动)

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10</span>

echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

sudo apt-get update

sudo apt-get install -y mongodb-org

sudo apt-get install -y mongodb-org=3.4 mongodb-org-server=3.4 mongodb-org-shell=3.4 mongodb-org-mongos=3.4 mongodb-org-tools=3.4

然后用编辑器打开以下内容(在这个例子中使用VIM - 使用 :wq 写入并退出)
sudo vim /etc/systemd/system/mongodb.service

粘贴:

#Unit contains the dependencies to be satisfied before the service is started.
[Unit]
Description=MongoDB Database
After=network.target
Documentation=https://docs.mongodb.org/manual
# Service tells systemd, how the service should be started.
# Key `User` specifies that the server will run under the mongodb user and
# `ExecStart` defines the startup command for MongoDB server.
[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
# Install tells systemd when the service should be automatically started.
# `multi-user.target` means the server will be automatically started during boot.
[Install]
WantedBy=multi-user.target

然后继续重新加载和启动...

systemctl daemon-reload

sudo systemctl start mongodb

在所有这些操作之后,您可能只需要重新启动一下... 您可以使用以下命令来检查状态并启用:

sudo systemctl status mongodb
sudo systemctl enable mongodb

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接