简体   繁体   English

如何在 Ubuntu 21.04 上安装 mongodb?

[英]How can I install mongodb on Ubuntu 21.04?

我按照官方指南进行安装,但在检查状态时出现以下错误。

Active: failed (Result: core-dump) since

First remove previously installed files related to Mongodb首先删除之前安装的MongoDB相关文件

sudo service mongod stop 
sudo apt-get purge mongodb-org* 
sudo rm -r /var/log/mongodb 
sudo rm -r /var/lib/mongodb

After multiple install and uninstall I found the issue, with official guide, as of 13/08/2021 it does not have information on 21.04, but if you check in the command their only one thing is changing that is codename, 20.04 has focal, 18.04 bionic same way 21.04 has "hirsute"经过多次安装和卸载后,我发现了这个问题,官方指南,截至 2021 年 8 月 13 日,它没有关于 21.04 的信息,但是如果你检查命令,他们唯一的一件事就是代号,20.04 有焦点, 18.04 仿生与 21.04 具有“多毛”相同的方式在此处输入图像描述

you can check this by typing in terminal "lsb_release -dc"您可以通过输入终端“lsb_release -dc”来检查

在此处输入图像描述

command with correct codename具有正确代号的命令

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu hirsute/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
sudo apt-get install -y mongodb-org
sudo systemctl start mongod
sudo systemctl status mongod

run the able commands in order.按顺序运行能够的命令。

This works for me!这对我有用!

curl -fsSL https://www.mongodb.org/static/pgp/server-5.0.asc | \
    sudo tee /etc/apt/trusted.gpg.d/mongodb.asc > /dev/null
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | \
    sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install -y mongodb-org
sudo systemctl start mongod
sudo systemctl status mongod

I installed like Harish suggested but left it with Focal when creating the apt source list instead of Hirsute.我按照 Harish 的建议安装了,但在创建 apt 源列表而不是 Hirsute 时将其留给了 Focal。 Got same error as OP.得到与OP相同的错误。 Looked at /var/log/mongodb, noticed no mongod.log had been created so I created mongod.log file under /var/log/mongodb, then changed the owner to mongodb for mongod.log, restarted the service for mongod and it worked.查看 /var/log/mongodb,注意到没有创建 mongod.log,所以我在 /var/log/mongodb 下创建了 mongod.log 文件,然后将 mongod.log 的所有者更改为 mongodb,重新启动了 mongod 的服务工作。

sudo touch /var/log/mongodb/mongod.log
sudo chown mongodb:mongodb /var/log/mongodb/mongod.log
sudo systemctl restart mongod.service
sudo systemctl status mongod.service

目前,您可以按照 20.04 的安装指南进行操作,除了第 1 步 - 导入公钥之外,请改用以下内容:

wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo tee /etc/apt/trusted.gpg.d/mongodb.asc > /dev/null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM