对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

使用 .tgz Tarball 在 SUSE 上安装 MongoDB Community Edition

使用本教程手动安装 MongoDB 8.0 MongoDB Community EditionSUSELinuxEnterpriseMongoDB Server (SLES) 上的 ,使用下载的.tgz tarball。

本教程将安装 MongoDB 8.0 社区版。要安装不同的 MongoDB Community,使用此页面左上角的版本下拉菜单以选择该版本的文档。

虽然您可以按照本文档所述使用下载的 .tgz Tarball 手动安装MongoDB ,但我们建议您尽可能在系统上使用 zypper包管理器。使用包管理器会自动安装所需的所有依赖项,提供示例mongod.conf文件,并简化未来的升级和维护任务。

➤ 有关说明,请参阅使用 zypper 包管理器安装 MongoDB 。

使用 .tgz 包安装服务器时,您需要按照 mongosh 安装说明单独下载和安装 mongosh。

MongoDB 8.0 支持 x _8664 架构上的以下MongoDB Community Edition 64SUSELinux位 EnterpriseMongoDB Server (SLES) 版本:

  • SLES 15

MongoDB 仅支持这些平台的 64 位版本。

更多信息,请参阅平台支持。

在生产环境中部署MongoDB之前,请参阅《自管理部署的生产说明》文档,了解性能注意事项和配置建议。

使用以下命令安装MongoDB Community .tgz tarball 所需的依赖项:

sudo zypper install libcurl4 libopenssl1_1

请按照以下步骤从 .tgz 手动安装 MongoDB Community Edition。

1

安装所需的必备包后,请从以下链接下载 MongoDB Community tgz tarball:

➤

MongoDB 下载中心

  1. 在 Version 下拉列表中选择要下载的 MongoDB 版本。

  2. 在 Platform 下拉菜单中,选择您操作系统的版本和架构。

  3. 在 Package 下拉菜单中,选择 tgz。

  4. 单击 Download(连接)。

2

使用存档经理程序或 tar 命令提取文件。示例,在系统shell中,您可以使用 tar 命令进行提取:

tar -zxvf mongodb-*-8.0.12.tgz
3

MongoDB 二进制文件位于 tarball 的 bin/ 目录中。您可以执行以下任一操作:

  • 将二进制文件复制到 PATH 变量中列出的目录中,例如 /usr/local/bin(根据需要使用您的安装目录来更新 /path/to/the/mongodb-directory/)

    sudo cp /path/to/the/mongodb-directory/bin/* /usr/local/bin/
  • 创建指向 PATH 变量中所列目录的二进制文件的符号链接,例如 /usr/local/bin(根据需要使用您的安装目录更新 /path/to/the/mongodb-directory/):

    sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/
4

安装 mongosh 然后使用 MongoDB Shell 连接到您的部署。

Download the package for the version of mongosh you need from the MongoDB Download Center and uncompress the package.

请按照以下步骤运行 MongoDB Community Edition。 这些说明假设您使用的是默认设置。

1

创建 MongoDB 实例存储其数据的目录。例如:

sudo mkdir -p /var/lib/mongo

创建 MongoDB 实例用于存储日志的目录。例如:

sudo mkdir -p /var/log/mongodb

启动 MongoDB 进程的用户必须具有对这些目录的读取和写入权限。例如,如果你打算自己运行 MongoDB:

sudo chown `whoami` /var/lib/mongo # Or substitute another user
sudo chown `whoami` /var/log/mongodb # Or substitute another user
2

要运行 MongoDB,请在系统提示符下运行 mongod 进程。

mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork

有关命令行选项 --dbpath 和 --logpath 的详情,请参阅选项。

3

检查日志文件 /var/log/mongodb/mongod.log 中以下行的进程输出,验证 MongoDB 是否成功启动:

[initandlisten] waiting for connections on port 27017

可能会在进程输出中看到非严重警告。只要看到上述日志行,便可在 MongoDB 初次计算期间安心地忽略这些警告。

4

Start a mongosh session on the same host machine as the mongod. You can run mongosh without any command-line options to connect to a mongod that is running on your localhost with default port 27017.

mongosh

For more information on connecting using mongosh, such as to connect to a mongod instance running on a different host and/or port, see the mongosh documentation.

To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. For the driver documentation, see Start Developing with MongoDB.

默认情况下,MongoDB 会以将 bindIp 设为 127.0.0.1 来启动,从而绑定到本地主机网络接口。这意味着 mongod 只能接受来自同一计算机上运行的客户端的连接。远程客户端无法连接到 mongod,且 mongod 无法初始化副本集,除非将此值设为有效的网络接口。

该值可通过以下任一方式配置:

  • 在 MongoDB 配置文件中使用 bindIp,或

  • 通过命令行参数 --bind_ip

警告

将实例绑定到可公开访问的 IP 地址之前,必须保护集群免遭未经授权的访问。有关安全建议的完整列表,请参阅自管理部署的安全清单。至少应考虑启用身份验证和强化网络基础设施。

有关配置bindIp的详细信息,请参阅自托管部署中的IP绑定。