Docs 菜单
Docs 主页
/
MongoDB Manual
/ / / /

使用以下工具在 Windows 上安装 MongoDB Community: msiexec.exe

在此页面上

  • Overview
  • Considerations
  • 安装 MongoDB Community Edition
  • 从命令解释器启动 MongoDB 社区版
  • 将 MongoDB Community 版作为 Windows 服务运行
  • 其他注意事项

注意

MongoDB Atlas

MongoDB Atlas 是在云中托管的 MongoDB 服务选项,无需安装开销,并提供免费套餐,可以立即开始使用。

使用本教程安装 MongoDB 6.0 MongoDB Community EditionWindowsmsiexec.exe在命令行中使用 以无人值守的方式运行 上的 。这对于希望使用自动化部署 MongoDB 的系统管理员非常有用。

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

本教程使用命令行工具msiexec.exe在 Windows 上安装 MongoDB。要使用图形 MSI 安装程序安装 MongoDB,请参阅使用 MSI 安装程序安装 MongoDB。

MongoDB Shell ( mongosh ) 不随 MongoDB Server 一起安装。您需要按照mongosh 安装说明单独下载并安装mongosh

MongoDB 6.0 MongoDB Community Edition支持采用 x86_64 架构的以下 64 位 版本的 Windows:

  • Windows Server 2019

  • Windows 10 / Windows 服务器 2016

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

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

注意

适用于 Linux 的 Windows 子系统 (WSL) 不支持 MongoDB。要在 Linux 上运行 MongoDB,请使用受支持的 Linux 系统。

Oracle 为运行 Hyper-V 的 Windows 主机上的 VirtualBox 提供实验性支持。但是,Microsoft 不支持在 Hyper-V 上使用 VirtualBox。

Disable Hyper-V if you want to install MongoDB on Windows using VirtualBox.

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

请按照以下步骤,使用 msiexec.exeWindows 命令提示符/解释器 (cmd.exe) 中以无人值守的方式在 Windows 上安装 MongoDB Community Edition。

1

从以下链接下载 MongoDB 社区版 .msi 安装程序:

MongoDB 下载中心

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

  2. Platform 下拉菜单中,选择 Windows

  3. Package 下拉菜单中,选择 msi

  4. 单击 Download(连接)。

2

重要

您必须以 Administrator 身份打开命令解释器。

使用 .msi 安装程序安装所有 MongoDB 二进制文件,包括 MongoDB Compass

在命令解释器中,前往包含 .msi 安装二进制文件的目录并运行:

msiexec.exe /l*v mdbinstall.log /qb /i mongodb-windows-x86_64-6.0-signed.msi

该操作将二进制文件安装到默认目录 C:\Program Files\MongoDB\Server\6.0\bin

要为这些可执行文件指定其他安装位置,请添加 INSTALLLOCATION 值。

msiexec.exe /l*v mdbinstall.log /qb /i mongodb-windows-x86_64-6.0-signed.msi ^
INSTALLLOCATION="C:\MongoDB\Server\6.0\"

如要阻止安装 MongoDB Compass,必须显式包含 SHOULD_INSTALL_COMPASS="0" 参数。

msiexec.exe /l*v mdbinstall.log /qb /i mongodb-windows-x86_64-6.0-signed.msi ^
SHOULD_INSTALL_COMPASS="0"

要安装特定的 MongoDB 组件集,您可以使用逗号分隔的列表在 ADDLOCAL 参数中指定它们,其中包括以下一个或多个组件集:

组件集名称
组件集中包含的二进制文件
ServerNoService
ServerService
mongod.exe 设置为 Windows 服务。
Router
MiscellaneousTools
mongodecrypt.exe, mongokerberos.exe, mongoldap.exe

例如,要使用旧版 mongo 客户端安装 MongoDB 服务器 (mongod.exe),然后将 MongoDB 服务器设置为 Windows 服务,请运行以下命令:

msiexec.exe /l*v mdbinstall.log /qb /i mongodb-windows-x86_64-6.0-signed.msi ^
ADDLOCAL="ServerService,LegacyClient" ^
SHOULD_INSTALL_COMPASS="0"

要在安装中包含 Compass,请删除 SHOULD_INSTALL_COMPASS="0"

Administrator 身份打开 Windows 命令提示/解释器 (cmd.exe)。

重要

您必须以 Administrator 身份打开命令解释器。

1

Create the data directory where MongoDB stores data. MongoDB's default data directory path is the absolute path \data\db on the drive from which you start MongoDB.

Command Interpreter 创建数据目录:

cd C:\
md "\data\db"
2

要启动 MongoDB,请运行 mongod.exe

"C:\Program Files\MongoDB\Server\6.0\bin\mongod.exe" --dbpath="c:\data\db"

The --dbpath option points to your database directory.

如果 MongoDB 数据库服务器运行正常,则Command Interpreter显示:

[initandlisten] waiting for connections

重要

根据 Windows 主机上的 Windows Defender 防火墙设置,Windows 可能会显示一个 Security Alert 对话框,提示阻塞 C:\Program Files\MongoDB\Server\6.0\bin\mongod.exe 的“某些功能”在网络上进行通信。要解决此问题,请执行以下操作:

  1. 单击 Private Networks, such as my home or work network(连接)。

  2. 单击 Allow access(连接)。

要了解有关安全和 MongoDB 的更多信息,请参阅安全文档。

3

如果尚未下载并安装 MongoDB Shell ( mongosh ),请按照 mongosh 安装说明 进行操作。

请务必在安装过程中将 mongosh.exe 二进制文件的路径添加到 PATH 环境变量中。

打开新的 Command Interpreter,然后输入 mongosh.exe 以连接 MongoDB。

有关使用 mongosh.exe 连接到 mongod (例如连接在其他主机和/或端口上运行的 MongoDB 实例)的更多信息,请参阅连接到部署。

有关 CRUD(创建、读取、更新、删除)操作的信息,请参阅:

您可以在安装过程中将 MongoDB 安装并配置为Windows Service ,MongoDB 服务会在安装成功后启动。

您还可以通过命令行手动管理该服务。要通过命令行启动 MongoDB 服务,请以 Administrator 身份打开 Windows 命令提示符/解释器 (cmd.exe),然后运行以下命令:

1

关闭所有其他命令提示符,然后调用以下命令:

net start MongoDB
2

检查 MongoDB 日志文件中是否有以下行:

[initandlisten] waiting for connections on port 27017

在启动过程的输出中,您可能会看到一些不关键的警告。只要在 MongoDB 日志中看到这条信息,您便可以在初步评估 MongoDB 时安全地忽略这些警告。

3

如果尚未下载并安装 MongoDB Shell ( mongosh ),请按照 mongosh 安装说明 进行操作。

请务必在安装过程中将 mongosh.exe 二进制文件的路径添加到 PATH 环境变量中。

打开新的 Command Interpreter,然后输入 mongosh.exe 以连接 MongoDB。

要停止/暂停 MongoDB 服务,可使用“服务”控制台:

  1. 在“服务”控制台中,找到 MongoDB 服务。

  2. 右键单击 MongoDB 服务,然后单击 Stop(停止)(或 Pause(暂停))。

您还可以通过命令行管理该服务。要通过命令行停止 MongoDB 服务,请以 Administrator 身份打开 Windows 命令提示符/解释器 (cmd.exe),然后运行以下命令:

net stop MongoDB

要删除 MongoDB 服务,请先使用“服务”控制台停止该服务。然后以 Administrator 的身份打开 Windows 命令提示符/解释器 (cmd.exe),并运行以下命令:

sc.exe delete MongoDB

By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod.exe can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod.exe, and the mongod.exe will not be able to initialize a replica set unless this value is set to a valid network interface which is accessible from the remote clients.

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

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

  • 通过命令行参数 --bind_ip

警告

在绑定到非本地主机(例如可公开访问)的 IP 地址之前,请确保您已保护集群免遭未经授权的访问。有关安全建议的完整列表,请参阅自托管部署的安全检查清单。至少应考虑启用身份验证强化网络基础架构。

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

如果您使用 Windows 安装程序 (.msi) 安装了 MongoDB,则 .msi 将在同一版本系列中自动进行升级(例如从7.2.1 至 7.2.2)。

升级完整版本系列(例如6.0 至 7.0)需要全新安装。

如果将C:\Program Files\MongoDB\Server\6.0\bin添加到系统PATH ,则可以省略 MongoDB Server 二进制文件的完整路径。如果还没有这样做,还应该添加mongosh的路径。

后退

在 Windows 上安装