在 Amazon Linux 上安装 MongoDB Enterprise Edition

在本页面

MongoDB Atlas and AWS

MongoDB Atlas是 AWS 上的托管 MongoDB 服务,用于启动,运行和维护 MongoDB 集群。

Overview

使用本教程,可以使用yum程序包 Management 器在 Amazon Linux 上安装 MongoDB 3.6 Enterprise Edition。

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

验证 Linux 发行版

您可以通过在命令行上运行以下命令来验证正在运行的 Linux 发行版:

grep ^NAME  /etc/*release

结果应为 Amazon Linux AMI 。如果使用其他 Linux 发行版,请参阅为您的平台安装说明

MongoDB Version

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

Considerations

Platform Support

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

  • Amazon Linux(2013.03 或更高版本)

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

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

Production Notes

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

安装 MongoDB 企业版

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

Configure repository.

创建一个/etc/yum.repos.d/mongodb-enterprise-3.6.repo文件,以便您可以使用yum直接安装 MongoDB 企业版:

[mongodb-enterprise-3.6]
name=MongoDB Enterprise Repository
baseurl=https://repo.mongodb.com/yum/amazon/2013.03/mongodb-enterprise/3.6/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc

Note

如果您在以前的 MongoDB 安装中的此目录中有mongodb-enterprise.repo文件,则应将其删除。使用上面的mongodb-enterprise-3.6.repo文件安装 MongoDB 3.6.

您也可以直接从MongoDB repository下载.rpm文件。下载按 Amazon Linux 版本(例如2013.03),MongoDB release version(例如3.6)和体系结构(例如x86_64)进行组织。奇数编号的 MongoDB 发布版本(例如3.7)是开发版本,不适合生产部署。

安装 MongoDB Enterprise 软件包。

安装 MongoDB Enterprise 的 3.6 版本候选版本。

发出以下命令:

sudo yum install -y mongodb-enterprise

安装特定版本的 MongoDB Enterprise。

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

sudo yum 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 Enterprise 版本,但是yum将在更新版本可用时升级软件包。为防止意外升级,请通过将以下exclude指令添加到/etc/yum.conf文件中来固定软件包:

exclude=mongodb-enterprise,mongodb-enterprise-server,mongodb-enterprise-shell,mongodb-enterprise-mongos,mongodb-enterprise-tools

运行 MongoDB 企业版

  • ulimit Considerations

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

    • 默认情况下,MongoDB 实例存储:
  • /var/lib/mongo中的数据文件

  • 其日志文件位于/var/log/mongodb

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

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

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

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

Procedure

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

Init System

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

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

ps --no-headers -o comm 1

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

  • systemd-选择下面的“ systemd(systemctl)”标签。

  • init-选择下面的“系统 V 初始化(服务)”标签。

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.

You can verify that the mongod process has started successfully by issuing the following command:

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.

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

sudo service mongod start

Verify that MongoDB has started successfully

You can verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading

[initandlisten] waiting for connections on port <port>

where <port> is the port configured in /etc/mongod.conf , 27017 by default.

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

sudo chkconfig mongod on

Stop MongoDB.

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

sudo service mongod stop

Restart MongoDB.

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

sudo service mongod restart

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.

Uninstall MongoDB

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

Warning

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

Stop MongoDB.

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

sudo service mongod stop

Remove Packages.

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

sudo yum erase $(sudo rpm -qa | grep mongodb-enterprise)

删除数据目录。

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

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

Additional Information

默认情况下,localhost 绑定

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

可以配置此值:

  • 在带有bindIp的 MongoDB 配置文件中,或者

  • 通过命令行参数--bind_ip

Warning

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

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

MongoDB 企业版软件包

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

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