在 Debian 上安装 MongoDB 企业版

在本页面

Overview

使用本教程,使用apt软件包 Management 器安装 MongoDB 3.6 Enterprise Edition。

MongoDB 企业版在某些平台上可用,并且包含对与安全性和监视有关的多种功能的支持。

MongoDB Version

本教程将安装 MongoDB 3.6 Enterprise Edition。要安装其他版本的 MongoDB Enterprise,请使用此页面左上角的版本下拉菜单选择该版本的文档。

Considerations

Platform Support

EOL Notice

MongoDB 3.6 Enterprise Edition 在x86_64体系结构上支持以下 64 位 Debian 版本:

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

有关更多信息,请参见Supported Platforms

Windows Subsystem for Linux (WSL) - Unsupported

MongoDB 不支持 Linux 的 Windows 子系统(WSL)。

Production Notes

在生产环境中部署 MongoDB 之前,请考虑Production Notes文档,该文档提供了生产 MongoDB 部署的性能注意事项和配置建议。

MongoDB 官方软件包

要在您的 Debian 系统上安装 MongoDB Enterprise,这些说明将使用官方的mongodb-enterprise软件包,该软件包由 MongoDB Inc.维护和支持。官方mongodb-enterprise软件包始终包含 MongoDB 的最新版本,可从其自己的专用存储库中获得。

Important

Debian 提供的mongodb软件包不是由 MongoDB Inc.维护,与官方的mongodb-enterprise软件包冲突。如果您已经在自己的 Debian 系统上安装了mongodb软件包,则必须先卸载mongodb软件包,然后再按照这些说明进行操作。

有关官方软件包的完整列表,请参见MongoDB 企业版软件包

安装 MongoDB 企业版

请按照以下步骤使用apt程序包 Management 器安装 MongoDB 企业版。

导入软件包 Management 系统使用的公钥。

在终端上,发出以下命令以从https://www.mongodb.org/static/pgp/server-3.6.asc导入 MongoDB 公共 GPG 密钥:

wget -qO - https://www.mongodb.org/static/pgp/server-3.6.asc | sudo apt-key add -

该操作应以OK响应。

为 MongoDB 创建一个/etc/apt/sources.list.d/mongodb-enterprise.list 文件。

使用适合您的 Debian 版本的命令创建列表文件:

回声“ deb http://repo.mongodb.com/apt/debian jessie/mongodb-enterprise/3.6 main” | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list


 - Debian 9 "Stretch"

   - ```sh
echo "deb http://repo.mongodb.com/apt/debian stretch/mongodb-enterprise/3.6 main" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list

如果要从特定的release series(例如 3.4)安装 MongoDB Enterprise 软件包,可以在存储库配置中指定发行系列。例如,要将系统限制为 3.4 版本系列,请添加以下存储库:

echo "deb http://repo.mongodb.com/apt/debian wheezy/mongodb-enterprise/3.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise-3.4.list

当前,软件包可用于 Debian 8“ Jessie”和 Debian 9“ Stretch”。

重新加载本地软件包数据库。

发出以下命令以重新加载本地软件包数据库:

sudo apt-get update

安装 MongoDB Enterprise 软件包。

安装 MongoDB Enterprise 3.6 版。

发出以下命令:

sudo apt-get install -y mongodb-enterprise

安装特定版本的 MongoDB Enterprise。

要安装特定发行版,必须分别指定每个组件包以及版本号,如以下示例所示:

sudo apt-get install -y mongodb-enterprise=3.6.19 mongodb-enterprise-server=3.6.19 mongodb-enterprise-shell=3.6.19 mongodb-enterprise-mongos=3.6.19 mongodb-enterprise-tools=3.6.19

如果您仅安装mongodb-enterprise=3.6.19并且不包括组件包,则无论您指定哪个版本,都将安装每个 MongoDB 包的最新版本。

固定特定版本的 MongoDB Enterprise。

尽管您可以指定任何可用的 MongoDB 版本,但是apt-get将在更新版本可用时升级软件包。为防止意外升级,请固定包装。要将 MongoDB 的版本固定为当前安装的版本,请发出以下命令序列:

echo "mongodb-enterprise hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-server hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-shell hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-mongos hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-tools hold" | sudo dpkg --set-selections

运行 MongoDB 企业版

默认情况下,MongoDB 实例存储:

如果通过程序包 Management 器安装,则这些默认目录是在安装过程中创建的。

如果通过下载压缩包手动安装,则可以使用mkdir -p <directory>sudo mkdir -p <directory>创建目录,具体取决于将运行 MongoDB 的用户。 (有关mkdirsudo的信息,请参见您的 Linux 手册页.)

默认情况下,MongoDB 使用mongodb用户帐户运行。如果您更改运行 MongoDB 进程的用户,则必须**还修改对/var/lib/mongodb/var/log/mongodb目录的权限,以使该用户可以访问这些目录。

要指定其他日志文件目录和数据文件目录,请编辑/etc/mongod.conf中的systemLog.pathstorage.dbPath设置。确保运行 MongoDB 的用户有权访问这些目录。

大多数类 Unixos 都限制了会话可能使用的系统资源。这些限制可能会对 MongoDB 的运行产生负面影响。有关更多信息,请参见UNIX ulimit 设置

Procedure

请按照以下步骤在系统上运行 MongoDB 企业版。这些说明假定您使用的是官方的mongodb-enterprise软件包,而不是 Debian 提供的非官方的mongodb软件包,并且使用的是默认设置。

Init System

要运行和 Managementmongod进程,您将使用 os 的内置init system。最新版本的 Linux 倾向于使用 systemd (使用systemctl命令),而较早版本的 Linux 倾向于使用 System V init (使用service命令)。

如果不确定平台使用哪个初始化系统,请运行以下命令:

ps --no-headers -o comm 1

然后根据结果在下面选择适当的选项卡:

systemd (systemctl)
System V Init (service)

Start MongoDB.

You can start the mongod process by issuing the following command:

sudo systemctl start mongod

If you receive an error similar to the following when starting mongod:

Failed to start mongod.service: Unit mongod.service not found.

Run the following command first:

sudo systemctl daemon-reload

Then run the start command above again.

Verify that MongoDB has started successfully.

sudo systemctl status mongod

You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:

sudo systemctl enable mongod

Stop MongoDB.

As needed, you can stop the mongod process by issuing the following command:

sudo systemctl stop mongod

Restart MongoDB.

You can restart the mongod process by issuing the following command:

sudo systemctl restart mongod

You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.

Begin using MongoDB.

Start a mongo shell on the same host machine as the mongod. Use the --host command line option to specify the localhost address and port that the mongod listens on:

mongo --host 127.0.0.1:27017

Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

Start MongoDB.

Issue the following command to start mongod:

sudo service mongod start

Verify that MongoDB has started successfully

Verify that the mongod process has started successfully:

sudo service mongod status

You can also check the log file for the current status of the mongod process, located at: /var/log/mongodb/mongod.log by default. A running mongod instance will indicate that it is ready for connections with the following line:

[initandlisten] waiting for connections on port 27017

Stop MongoDB.

As needed, you can stop the mongod process by issuing the following command:

sudo service mongod stop

Restart MongoDB.

Issue the following command to restart mongod:

sudo service mongod restart

Begin using MongoDB.

Start a mongo shell on the same host machine as the mongod. Use the --host command line option to specify the localhost address and port that the mongod listens on:

mongo --host 127.0.0.1:27017

Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

Uninstall MongoDB

要从系统中完全删除 MongoDB,必须删除 MongoDB 应用程序本身,配置文件以及任何包含数据和日志的目录。以下部分将指导您完成必要的步骤。

Warning

此过程将“完全”删除 MongoDB,其配置和“所有”数据库。此过程是不可逆的,因此请确保在 continue 操作之前备份所有配置和数据。

Stop MongoDB.

通过发出以下命令来停止mongod进程:

sudo service mongod stop

Remove Packages.

删除以前安装的所有 MongoDB 软件包。

sudo apt-get purge mongodb-enterprise*

删除数据目录。

删除 MongoDB 数据库和日志文件。

sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb

Additional Information

默认情况下,localhost 绑定

默认情况下,MongoDB 在bindIp设置为127.0.0.1的情况下启动,该绑定到 localhost 网络接口。这意味着mongod仅可以接受来自同一计算机上运行的 Client 端的连接。远程 Client 端将无法连接到mongod,并且mongod将无法初始化replica set,除非将此值设置为有效的网络接口。

可以配置此值:

Warning

绑定到非 localhost(例如可公开访问)的 IP 地址之前,请确保已保护群集免受未经授权的访问。有关安全建议的完整列表,请参见Security Checklist。至少考虑enabling authentication加强网络基础设施

有关配置bindIp的更多信息,请参见MongoDB 配置强化

MongoDB 企业版软件包

MongoDB Enterprise Edition 可从其自己的专用存储库中获得,并且包含以下官方支持的软件包:

Package Name Description
mongodb-enterprise metapackage将自动安装下面列出的四个组件包。
mongodb-enterprise-server 包含mongod守护程序以及相关的配置和初始化脚本。
mongodb-enterprise-mongos 包含mongos守护程序。
mongodb-enterprise-shell 包含mongo shell。
mongodb-enterprise-tools 包含以下 MongoDB 工具:mongoimport bsondumpmongodumpmongoexportmongofilesmongoperfmongorestoremongostatmongotop
首页