重要
MongoDB 8.2 是最新的次要发布。从MongoDB 8.2 开始,次要版本可用于特定使用案例的本地部署部署(MongoDB Community和 Enterprise)。有关更多信息,请参阅 MongoDB版本控制。
要安装支持本地部署使用的最新MongoDB版本,请参阅安装说明。
公钥检索错误
Import the public key used by the package management system在安装MongoDB Community Edition的 步骤中出现。
gpg: no valid OpenPGP data found.
解决方案
完全按照文档要求复制命令。该操作应以 OK 进行响应。
验证系统中是否存在MongoDB公共 GPG 密钥:
sudo apt-key list
预期输出如下:
/etc/apt/trusted.gpg -------------------- pub rsa4096 2018-04-18 [SC] [expires: 2023-04-17] E162 F504 A20C DF15 827F 718D 4B7C 549A 058F 8B6B uid [ unknown] MongoDB 8.0 Release Signing Key <packaging@mongodb.com>
sudo apt update Errors
sudo apt update在作为 Install MongoDB Community Edition过程的一部分运行 之后发生。通常是由于缺少MongoDB公共 GPG 密钥造成的。
W: GPG error: https://repo.mongodb.org/apt/ubuntu <release>/mongodb-org/8.2 Release: \ The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4B7C549A058F8B6B E: The repository 'https://repo.mongodb.org/apt/ubuntu <release>/mongodb-org/8.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.
解决方案
Import the public key used by the package management system重复安装MongoDB Community Edition中的 步骤。完全按照文档要求复制命令和密钥。
验证密钥:
sudo apt-key list
预期输出:
-------------------- pub rsa4096 2018-04-18 [SC] [expires: 2023-04-17] E162 F504 A20C DF15 827F 718D 4B7C 549A 058F 8B6B uid [ unknown] MongoDB 8.0 Release Signing Key <packaging@mongodb.com>
sudo apt install -y mongodb-org Errors
在“安装MongoDB Community Edition”过程的步骤 中运行sudo apt install -y mongodb-org Create a list file for MongoDB后出现。通常由/etc/apt/sources.list.d/mongodb-org-8.2.list 文件丢失或配置错误引起。
Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package mongodb-org
解决方案
检查文件内容:
cat /etc/apt/sources.list.d/mongodb-org-8.2.list 如果内容与您的Ubuntu版本的文档不匹配,删除该文件并重复 Create a list file for MongoDB 步骤。
如果该文件不存在,请在该步骤中创建它。
更新存储库并重试安装:
sudo apt update sudo apt install -y mongodb-org
dpkg-deb: error 包冲突
sudo apt install -y mongodb-org在“安装MongoDB Community Edition”过程的 步骤中出现。通常由已安装的Ubuntumongodb 包发生冲突所致。
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-server_8.2.0_amd64.deb (--unpack): trying to overwrite '/usr/bin/mongod', which is also in package mongodb-server-core 1:3.6.3-0ubuntu1
解决方案
检查冲突:
sudo apt list --installed | grep mongo
mongodb/bionic,now 1:3.6.3-0ubuntu1 amd64 [installed] mongodb-clients/bionic,now 1:3.6.3-0ubuntu1 amd64 [installed,automatic] mongodb-server/bionic,bionic,now 1:3.6.3-0ubuntu1 all [installed,automatic] mongodb-server-core/bionic,now 1:3.6.3-0ubuntu1 amd64 [installed,automatic]
如果输出显示如下所示的Ubuntu包,请将其删除:
sudo apt remove mongodb sudo apt purge mongodb sudo apt autoremove
注意
sudo apt purge mongodb 删除默认配置文件。要保留修改后的配置文件,请在清除之前将其复制到另一个目录(例如 /home/your-user-name)。
对于混合包:
如果输出同时显示mongodb-org 和mongodb 包,请先删除mongodb-org ,然后删除mongodb 包。清除所有MongoDB相关包后,重试安装MongoDB Community Edition。
mongod 套接字错误
mongod启动mongod 时发生。通常由另一个进程(通常是另一个 )使用已配置的端口引起。
Socket is already in use
Failed to unlink socket file
解决方案
识别进程:
以下示例使用 ss 列出处于 LISTEN (-l) 状态的所有打开的 TCP (-t) 和 UDP (-u) 套接字以及使用每个套接字 (-p) 的进程,而无需解析任何服务名称或主机名 (-n):
sudo ss -tulpn
输出示例在端口 27017 上显示 mongod:
Netid State Local Address:Port udp UNCONN 127.0.0.53%lo:53 users:(("systemd-resolve",pid=663,fd=12)) udp UNCONN 10.1.16.87%enp0s3:68 users:(("systemd-network",pid=652,fd=15)) tcp LISTEN 127.0.0.53%lo:53 users:(("systemd-resolve",pid=663,fd=13)) tcp LISTEN 0.0.0.0:22 users:(("sshd",pid=819,fd=3)) tcp LISTEN 192.168.1.15:27017 users:(("mongod",pid=10027,fd=12)) tcp LISTEN 127.0.0.1:27017 users:(("mongod",pid=10027,fd=11)) tcp LISTEN ::]:22 users:(("sshd",pid=819,fd=4))
您可以执行以下任一操作:
数据目录错误
出现在 进程日志中。通常由不存在或可供mongod 访问的数据目录引起。mongod
Data directory ... not found Attempted to create lock file on a read-only directory: ...
作为服务(sudo systemctl start mongod 或 sudo
service mongod start)启动时,这可能平均值:
从终端启动时,这可能平均值:
解决方案
根据原因,创建数据目录或设立适当的权限和所有权。
创建目录:
storage.dbPath在配置文件中使用 或在命令行中使用--dbpath数据目录。设置默认路径:
apt包管理器安装:默认的/etc/mongod.conf配置文件将storage.dbPath设置为/var/lib/mongodb
确保数据目录存在,或在启动
mkdir之前使用mongod创建目录。设置目录权限:
设置适当的权限和所有权:
需要
mongodrwx(读取、写入、执行)权限