当我尝试使用 16.04 上的说明安装 mongodb 时,https://docs.mongodb.com/getting-started/shell/tutorial/install-mongodb-on-ubuntu/
在安装步骤中得到以下结果:
jonathan@poseidon:~$ sudo apt-get install mongodb-org
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package mongodb-org is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'mongodb-org' has no installation candidate
我使用 Wireshark 检查了 HTTP 流量,发现唯一的流量是列表的 HTTP GET 和 HTTP 304 响应,这表明问题出在我的本地配置文件中。我的 sources.list.d 文件包含以下条目:
mongodb-org-3.4.list
我需要做什么才能继续解决这个问题?
编辑:我尝试在 VirtualBox 下新安装的 16.04 上再次执行此操作。我检索了密钥,创建了列表文件,并执行了sudo apt update
以下结果:
jonathan@Ubuntu-16:~$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
[sudo] password for jonathan:
Executing: /tmp/tmp.uWYpRUWfjK/gpg.1.sh --keyserver
hkp://keyserver.ubuntu.com:80
--recv
0C49F3730359A14518585931BC711F9BA15703C6
gpg: requesting key A15703C6 from hkp server keyserver.ubuntu.com
gpg: key A15703C6: public key "MongoDB 3.4 Release Signing Key <[email protected]>" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
jonathan@Ubuntu-16:~$ echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse
jonathan@Ubuntu-16:~$ sudo apt update
Ign:1 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 InRelease
Get:2 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release [3 462 B]
Hit:3 http://mx.archive.ubuntu.com/ubuntu xenial InRelease
Get:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [94.5 kB]
Get:5 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release.gpg [801 B]
Get:6 http://mx.archive.ubuntu.com/ubuntu xenial-updates InRelease [95.7 kB]
Ign:5 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release.gpg
Get:7 http://mx.archive.ubuntu.com/ubuntu xenial-backports InRelease [92.2 kB]
Reading package lists... Done
W: GPG error: http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY D68FA50FEA312927
E: The repository 'http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
jonathan@Ubuntu-16:~$
如您所见,检索到的密钥适用于 Mongodb 3.4,而不是 Mongodb 3.2,这解释了 apt 更新中的 GPG 失败。有人知道在哪里可以获取正确的密钥吗?
答案1
Ubuntu 18.04 和 MongoDB 4.2
首先,如果之前安装了 MongoDB,请将其删除:
sudo apt remove --autoremove mongodb-org
删除所有 mongodb repo 列表文件:
sudo rm /etc/apt/sources.list.d/mongodb*.list
sudo apt update
现在,添加新密钥:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 4B7C549A058F8B6B
添加新的存储库:
echo "deb [arch=amd64] http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
安装 MongoDB
sudo apt update
sudo apt install mongodb-org
启用并启动mongod
服务器服务:
systemctl enable mongod.service
systemctl start mongod.service
检查你的安装:
~$ mongo --version
MongoDB shell version v4.2.2
git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
allocator: tcmalloc
modules: none
build environment:
distmod: ubuntu1804
distarch: x86_64
target_arch: x86_64
您还可以检查您的服务是否已启动:
~$ systemctl status mongod.service
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: e
Active: active (running) since Mon 2019-12-30 08:05:48 MST; 1min 7s ago
Docs: https://docs.mongodb.org/manual
Main PID: 7941 (mongod)
CGroup: /system.slice/mongod.service
└─7941 /usr/bin/mongod --config /etc/mongod.conf
Ubuntu 20.04 和 MongoDB 4.4 或 MongoDB 5.0
首先,如果之前安装了 MongoDB,请将其删除:
systemctl stop mongod.service
systemctl disable mongod.service
sudo apt remove --autoremove mongodb-org
删除所有 mongodb repo 列表文件:
sudo rm /etc/apt/sources.list.d/mongodb*.list
sudo apt update
现在,添加新密钥MongoDB 4.4:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 656408E390CFB1F5
新的关键MongoDB 5.0:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv B00A0BD1E2C63C11
添加新的存储库MongoDB 4.4:
echo "deb [arch=amd64] http://repo.mongodb.org/apt/ubuntu $(lsb_release -sc)/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org.list
或者新的存储库MongoDB 5.0:
echo "deb [arch=amd64] http://repo.mongodb.org/apt/ubuntu $(lsb_release -sc)/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org.list
安装 MongoDB
sudo apt update
sudo apt install mongodb-org
启用并启动mongod
服务器服务:
systemctl enable mongod.service
systemctl start mongod.service
检查你的安装:
~$ mongo --version
MongoDB shell version v4.4.3
Build Info: {
"version": "4.4.3",
"gitVersion": "913d6b62acfbb344dde1b116f4161360acd8fd13",
"openSSLVersion": "OpenSSL 1.1.1f 31 Mar 2020",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "ubuntu2004",
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
或者
$ mongo --version
MongoDB shell version v5.0.2
Build Info: {
"version": "5.0.2",
"gitVersion": "6d9ec525e78465dcecadcff99cce953d380fedc8",
"openSSLVersion": "OpenSSL 1.1.1f 31 Mar 2020",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "ubuntu2004",
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
您还可以检查您的服务是否已启动:
~$ systemctl status mongod.service
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset>
Active: active (running) since Sun 2021-01-24 07:52:50 MST; 27s ago
Docs: https://docs.mongodb.org/manual
Main PID: 2353629 (mongod)
Memory: 59.2M
CGroup: /system.slice/mongod.service
└─2353629 /usr/bin/mongod --config /etc/mongod.conf
Jan 24 07:52:50 terrance-ubuntu systemd[1]: Started MongoDB Database Server.
Ubuntu 22.04 和 MongoDB 6.0
MongoDB 存储库尚未 100% 为 22.04 做好准备,因此您必须使用其中的 Focal 存储库来安装它。此外,由于 apt-key 现已弃用,因此存储库没有为 GPG 准备好的密钥,但这些说明目前仍然有效。
首先,如果之前安装了 MongoDB,请将其删除:
systemctl stop mongod.service
systemctl disable mongod.service
sudo apt remove --autoremove mongodb-org
删除所有 mongodb repo 列表文件:
sudo rm /etc/apt/sources.list.d/mongodb*.list
sudo apt update
在执行下一步之前,您可能需要安装 gpg。
sudo apt install gpg
现在,添加新密钥MongoDB 6.0:
curl -fsSL https://pgp.mongodb.com/server-6.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb60.gpg
添加新的存储库MongoDB 6.0 (您必须使用 Focal repo,因为 Jammy repo 不包含mongodb-org
mongod 服务器的安装):
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/mongodb60.gpg] http://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org.list
安装 MongoDB
sudo apt update
sudo apt install mongodb-org
启用并启动mongod
服务器服务:
systemctl enable mongod.service
systemctl start mongod.service
检查你的安装:
mongod --version
db version v6.0.2
Build Info: {
"version": "6.0.2",
"gitVersion": "94fb7dfc8b974f1f5343e7ea394d0d9deedba50e",
"openSSLVersion": "OpenSSL 1.1.1f 31 Mar 2020",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "ubuntu2004",
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
systemctl status mongod.service
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset>
Active: active (running) since Thu 2022-10-13 08:13:21 MDT; 39s ago
Docs: https://docs.mongodb.org/manual
Main PID: 44048 (mongod)
Memory: 68.1M
CPU: 1.169s
CGroup: /system.slice/mongod.service
└─44048 /usr/bin/mongod --config /etc/mongod.conf
Oct 13 08:13:21 terrance-ubuntu systemd[1]: Started MongoDB Database Server.
希望这可以帮助!
答案2
除了 @Terrance 的答案之外,您还可以通过以下方法找到合适的签名密钥。本例适用于 mongodb,但也可以类似地用于任何其他包。在执行 @Terrance 的答案之前:
去ubuntu 密钥服务器找到真正的钥匙
搜索感兴趣的字符串(在本例中为 mongodb)并提交第一个表单(不需要第二个表单)-单击
Search!
按钮
- 在提供的搜索列表中寻找您的版本(在我这里的例子里是 3.4)
您可以在那里看到两行带有键的行。关注最实际的日期。第一个字符串是创建日期,而第二个字符串是有效到期日期。
使用第 5 点中提到的行中的签名 - 如果从图片来看
A15703C6
继续 Terrance 的回答,无论您是否需要安装软件包或像我一样升级
答案3
第一次运行:
$ sudo rm /etc/apt/sources.list.d/mongodb*.list
建议还从/etc/apt/sources.list
文件中删除与 MongoDB 相关的所有行。
然后使用提供的命令重新安装 MongoDBUbuntu 的官方 MongoDB 安装说明。
提供的链接中的命令如下
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
sudo apt-get install gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo service mongod start
sudo service mongod status
答案4
今天我在 Ubuntu 20.04.1 LTS (Focal Fossa) 中安装 mongodb 4.2 时遇到了困难。我是新用户,花了不少时间才搞清楚。@Terrance 写的答案帮我解决了问题。我按照以下步骤将它安装在我的系统中:
sudo rm /etc/apt/sources.list.d/mongodb*.list
sudo apt update
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 4B7C549A058F8B6B
echo "deb [arch=amd64] http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
sudo apt update
sudo apt install mongodb-org
希望这能帮助到其他人。谢谢。