

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 将自托管 MongoDB 环境迁移到 MongoDB Atlas AWS
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud"></a>

*Battulga Purevragchaa 和 Igor Alekseev，Amazon Web Services*

*Babu Srinivasan，MongoDB*

## Summary
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-summary"></a>

此模式描述了如何从自管理式 MongoDB 环境（包括 MongoDB Community Server、Enterprise Server、Enterprise Advanced、mLab 或任何托管的 MongoDB 集群）迁移到 AWS 云上的 MongoDB Atlas。它使用 [Atlas Live Migration Service](https://www.mongodb.com/cloud/atlas/migrate) 来帮助加速从 MongoDB 到 MongoDB Atlas 的数据迁移。

该模式与规范性指导网站上的《[迁移到 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-mongodb-atlas/)》 AWS 指南一起出现。其中提供了适用于该指南中讨论的其中一个迁移场景的实施步骤。有关其他迁移方案，请参阅 AWS 规范性指导网站上的以下模式：
+ [将关系数据库迁移到 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-relational-database-to-mongodb-atlas.html)
+ [将数据从 IBM Db2、SAP、Sybase 和其他数据库流式传输到 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/stream-data-from-ibm-db2-to-mongodb-atlas.html)

该模式适用于[AWS 系统集成商 (SI) 合作伙伴](https://aws.amazon.com/managed-services/partners/)和 AWS 用户。

## 先决条件和限制
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-prereqs"></a>

**先决条件**
+ 一个可迁移到 MongoDB Atlas 的源 MongoDB Enterprise Advanced、Community Server 或其他自管理式 MongoDB 环境。
+ 熟悉 MongoDB、MongoDB Atlas 和。 AWS 服务此模式从宏观层面阐述了部分迁移步骤。更多细节将在后续版本中添加。

**产品版本**
+ MongoDB 版本 6.0.13 或更高版本

## 架构
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-architecture"></a>

下图显示了 Atlas Live Migration Service，用于将数据从 MongoDB Enterprise Advanced 数据库和 MongoDB Community 数据库迁移到 AWS上的 MongoDB Atlas。如果您需要将大型复杂数据库迁移到 MongoDB Atlas，同时最大限度地减少停机时间并实现持续的数据同步，请使用此服务。此模式使用 Atlas Live Migration Service。

![\[使用 MongoDB Atlas Live Migration Service 迁移数据。\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/52cdb923-64ff-4ee2-b129-93b9a139e24b/images/372134c4-ba47-4e48-bd0d-8b43017773b8.png)


下图显示了 MongoDB 镜像服务 `mongomirror` ()，您还可以使用该服务通过安全连接将数据从 MongoDB 企业高级数据库和 MongoDB 社区数据库迁移到 MongoDB Atlas。 AWS [AWS PrivateLink](https://aws.amazon.com/privatelink/)使用 `mongomirror` 在本地 MongoDB 和 MongoDB Atlas 之间进行持续复制数据。此工具非常适合用于灾难恢复或分阶段迁移，但不在此模式的范围之内。

![\[使用 mongomirror 工具迁移数据。\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/52cdb923-64ff-4ee2-b129-93b9a139e24b/images/53488a9b-2210-4b3d-b517-b618c1e0182c.png)


有关更多支持不同使用场景的 MongoDB Atlas 参考架构，请参阅规范性指南网站上的[迁移到 MongoDB](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-mongodb-atlas/architecture.html) Atlas。 AWS AWS 

## 工具
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-tools"></a>
+ [MongoDB Atlas](https://www.mongodb.com/atlas) 是一种完全托管式数据库即服务（DbaaS），用于在云中部署和管理 MongoDB 数据库。
+ [Atlas Live Migration Service](https://www.mongodb.com/cloud/atlas/migrate) 是免费的 MongoDB 实用程序，可帮助将数据库迁移到 Atlas。此服务使源数据库与目标数据库保持同步，直到直接割接。当您准备好割接时，您可以停止应用程序实例，将它们指向目标 Atlas 集群，然后重新启动它们。要访问此服务，请从 MongoDB Atlas 集群中选择**数据库选项**。
+ [mongomirror](https://www.mongodb.com/docs/atlas/import/mongomirror/) 用于手动将数据从现有 MongoDB 副本集迁移到 MongoDB Atlas 副本集。`mongomirror` 不需要您关闭现有的副本集或应用程序，不会导入用户或角色数据，也不会复制配置数据库。可以从 [MongoDB 文档](https://www.mongodb.com/docs/atlas/import/mongomirror/#download-mongomirror)下载 `mongomirror`。

## 最佳实践
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-best-practices"></a>

有关在 AWS上使用 MongoDB 的最佳实践，请参阅合作伙伴网络博客[AWS 上的](https://aws.amazon.com/blogs/apn/tag/mongodb-atlas/)帖子。

## 操作说明
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-epics"></a>

### 发现与评测
<a name="discovery-and-assessment"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 确定集群大小。 | 使用 `db.stats()` 中关于总索引空间的信息来估计工作集大小。假设您的数据空间中有一定比例会被频繁访问。或者，您可以根据自己的假设来估计内存需求。此任务大约需要一周时间。有关此场景以及此操作说明中其他场景的详细信息和示例，请参阅[相关资源](#migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-resources)部分。 | 数据库管理员、应用程序所有者 | 
| 估计网络带宽要求。 | 要估计网络带宽要求，请将平均文档大小乘以每秒提供的文档数量。考虑集群中任何节点将承受的最大流量作为基础。要计算从集群到客户端应用程序的下游数据传输速率，请使用一段时间内返回的文档总数的总和。如果您的应用程序从辅助节点读取数据，请将文档总数除以可以提供读取操作的节点数。要查找数据库的平均文档大小，请使用 `db.stats().avgObjSize` 命令。此任务通常需要一天的时间。 | 数据库管理员 | 
| 选择 Atlas 层。 | 按照 [MongoDB 文档](https://www.mongodb.com/docs/atlas/sizing-tier-selection/)中的说明选择正确的 Atlas 集群层。 | 数据库管理员 | 
| 制定割接计划。 | 制定应用程序割接计划。 | 数据库管理员、应用程序所有者 | 

### 在 AWS 上设置新的 MongoDB Atlas 环境
<a name="set-up-a-new-mongodb-atlas-environment-on-aws"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 在上创建新的 MongoDB Atlas 集群。 AWS | 登录 Atlas 并打开项目的**概述**页面。选择**创建**按钮以创建集群。有关更多信息，请参阅 [MongoDB 文档](https://www.mongodb.com/docs/atlas/tutorial/deploy-free-tier-cluster/)。 | 数据库管理员 | 
| 选择 AWS 区域 和全局群集配置。 | 从适用于您的 Atlas 集群 AWS 区域 的列表中进行选择。如果需要，请配置全局集群。有关更多信息，请参阅 [MongoDB 文档](https://www.mongodb.com/docs/atlas/tutorial/deploy-free-tier-cluster/#select-your-preferred-region.)。 | 数据库管理员 | 
| 选择集群层。 | 选择您的首选集群层。您的层选择决定了内存、存储和 IOPS 规格等因素。 | 数据库管理员 | 
| 配置其他集群设置。 | 配置其他集群设置，例如 MongoDB 版本、备份和加密选项。有关这些选项的更多信息，请参阅[相关资源](#migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-resources)部分。 | 数据库管理员 | 

### 配置安全性和合规性
<a name="configure-security-and-compliance"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 对用户进行身份验证和授权。 | 您必须创建并验证将访问 MongoDB Atlas 集群的数据库用户。要访问项目中的集群，用户必须属于该项目，并且他们可以属于多个项目。 Atlas 还支持基于 AWS Identity and Access Management (IAM) 的身份验证。有关更多信息，请参阅 [MongoDB 文档](https://www.mongodb.com/docs/atlas/security/aws-iam-authentication/#set-up-authentication-with-aws-iam)。 | 数据库管理员 | 
| 创建自定义角色。 | （可选）Atlas 支持在内置的 Atlas 数据库用户权限未涵盖所需权限集的情况下创建自定义角色。 | 数据库管理员 | 
| 设置 VPC 对等连接。 | （可选）Atlas 支持[虚拟私有云 (VPC) 与其他开](https://docs.aws.amazon.com/vpc/latest/peering/what-is-vpc-peering.html)启的 VPCs 对 AWS等。 | AWS 管理员 | 
| 设置 AWS PrivateLink 终端节点。 | （可选）您可以使用在上 AWS 设置私有终端节点 AWS PrivateLink。有关更多信息，请参阅 [Amazon VPC 文档](https://docs.aws.amazon.com/vpc/latest/userguide/endpoint-services-overview.html)。 | AWS 管理员 | 
| 启用双因素身份验证。 | （可选）Atlas 支持双因素身份验证 (2FA)，以帮助用户控制对其 Atlas 账户的访问。 | AWS 管理员 | 
| 使用 LDAP 设置用户身份验证和授权。 | （可选）Atlas支持使用轻量级目录访问协议 (LDAP) 执行用户身份验证和授权。 | AWS 管理员 | 
| 设置统一 AWS 接入。 | （可选）某些 Atlas 功能（包括 Atlas 数据湖和使用客户密钥管理的静态加密）使用 IAM 角色进行身份验证。 | AWS 管理员 | 
| 使用设置静态加密 AWS KMS。 | （可选）Atlas 支持使用 AWS Key Management Service (AWS KMS) 加密存储引擎和云提供商备份。 | AWS 管理员 | 
| 设置客户端字段级加密。 | （可选）Atlas 支持客户端字段级加密，包括字段的自动加密。 | AWS 管理员 | 

### 迁移数据
<a name="migrate-data"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 在 MongoDB Atlas 中选择目标副本集。 | 导航到目标 Atlas 集群并选择省略号（...）按钮。在集群列表中，此按钮显示在集群名称下方。在集群详细信息中，按钮显示在右侧，位于**连接**和**配置**按钮旁边。有关更多信息，请参阅 [MongoDB 文档](https://www.mongodb.com/docs/atlas/import/c2c-pull-live-migration/#procedure)。 | 数据库管理员 | 
| 将 Atlas Live Migration Service 添加到访问列表。 | 将 Atlas 实时迁移服务添加到 AWS 源集群的访问列表中。这有助于准备源环境以连接到目标 Atlas 集群。 | 数据库管理员 | 
| 使用 Atlas Live Migration Service 执行迁移。 | 选择**开始迁移**。当**准备割接**按钮变绿时，执行割接。查看 Atlas 集群性能指标。考虑更新所有应用程序层中的数据库连接以指向新数据库。 | 数据库管理员 | 

### 配置操作集成
<a name="configure-operational-integration"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 连接到 MongoDB Atlas 集群。 | 确保 MongoDB Atlas 集群连接按预期运行。 | 应用程序所有者 | 
| 与集群数据交互。 | 测试集群数据。 | 数据库管理员 | 
| 监控您的集群。 | 验证集群设置是否正确。 | 数据库管理员 | 
| 备份和恢复集群数据。 | 为集群数据安排定期备份计划。 | 数据库管理员 | 

## 问题排查
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-troubleshooting"></a>


| 问题 | 解决方案 | 
| --- | --- | 
| 错误：无法访问指定的源 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud.html) | 
| 错误：无法解析主机名 | 找不到给定主机名的 IP 地址。确认给定的主机名正确且可公开访问。 | 
| 任何其它错误 | 如遇任何其他错误，请参阅 MongoDB 文档中的[实时迁移故障排除（拉取）](https://www.mongodb.com/docs/atlas/import/live-import-troubleshooting/)。 | 

## 相关资源
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-resources"></a>

除非另有说明，否则以下所有链接均指向 MongoDB 文档中的网页。

**迁移指南**
+ [在（规范性指南）上迁移到 MongoDB Atla AWS s](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-mongodb-atlas/)AWS 

**旧版迁移**
+ [迁移较旧版本的 MongoDB](https://www.mongodb.com/docs/atlas/legacy-migration/)

**发现与评测**
+ [内存](https://docs.atlas.mongodb.com/sizing-tier-selection/#memory)
+ [使用 Atlas 示例数据集进行大小调整示例](https://www.mongodb.com/docs/atlas/sizing-tier-selection/#example--the-service-sample-data-sets)
+ [移动应用程序的大小调整示例](https://www.mongodb.com/docs/atlas/sizing-tier-selection/#example--mobile-app)
+ [网络流量](https://docs.atlas.mongodb.com/sizing-tier-selection/#network-traffic)
+ [集群自动扩缩](https://www.mongodb.com/docs/atlas/sizing-tier-selection/#cluster-auto-scaling)
+ [Atlas 大小调整模板](https://view.highspot.com/viewer/5f438f47a4dfa042e97130c5)

**配置安全性和合规性**
+ [配置 IP 访问列表条目](https://docs.atlas.mongodb.com/security/ip-access-list/)
+ [配置数据库用户](https://docs.atlas.mongodb.com/security-add-mongodb-users/)
+ [配置对 Atlas UI 的访问权限](https://docs.atlas.mongodb.com/organizations-projects/)
+ [配置自定义数据库角色](https://docs.atlas.mongodb.com/security-add-mongodb-roles)
+ [配置数据库用户](https://docs.atlas.mongodb.com/security-add-mongodb-users/#atlas-user-privileges)
+ [设置网络对等连接](https://docs.atlas.mongodb.com/security-vpc-peering/)
+ [了解 Atlas 中的私有端点](https://docs.atlas.mongodb.com/security-private-endpoint/)
+ [管理多重身份验证选项](https://docs.atlas.mongodb.com/security-two-factor-authentication/)
+ [使用 LDAP 设置用户身份验证和授权](https://docs.atlas.mongodb.com/security-ldaps/)
+ [Atlas 数据湖](https://docs.mongodb.com/datalake/)
+ [使用客户密钥管理进行静态加密](https://docs.atlas.mongodb.com/security-kms-encryption/)
+ [承担角色的方法](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html)（IAM 文档）
+ [客户端字段级加密](https://docs.mongodb.com/manual/core/security-client-side-encryption)
+ [自动加密](https://docs.mongodb.com/manual/core/security-automatic-client-side-encryption) 
+ [MongoDB Atlas 安全控制](https://webassets.mongodb.com/_com_assets/cms/MongoDB_Atlas_Security_Controls-v7k3rbhi3p.pdf)
+ [MongoDB 信任中心](https://www.mongodb.com/cloud/trust)
+ [为集群配置安全功能](https://docs.atlas.mongodb.com/setup-cluster-security/)

**在 **AWS** 上设置新的 MongoDB Atlas 环境**
+ [云提供商和地区](https://docs.atlas.mongodb.com/cloud-providers-regions/)
+ [管理全局集群](https://docs.atlas.mongodb.com/global-clusters/)
+ [选择集群层级](https://www.mongodb.com/docs/atlas/manage-clusters/#select-cluster-tier)
+ [配置其他设置](https://docs.atlas.mongodb.com/cluster-additional-settings/)
+ [开始使用 Atlas](https://docs.atlas.mongodb.com/getting-started/)
+ [配置对 Atlas UI 的访问权限](https://docs.atlas.mongodb.com/organizations-projects/)

**迁移数据**
+ [迁移或导入数据](https://www.mongodb.com/docs/atlas/import/)

**监控集群**
+ [监控您的集群](https://docs.atlas.mongodb.com/monitoring-alerts/)

**集成操作**
+ [连接到集群](https://docs.atlas.mongodb.com/connect-to-cluster/)
+ [与您的数据交互](https://docs.atlas.mongodb.com/data-explorer/)
+ [监控您的集群](https://docs.atlas.mongodb.com/monitoring-alerts/)
+ [备份、恢复和存档数据](https://docs.atlas.mongodb.com/backup-restore-cluster/)

**训练**
+ [使用 MongoDB Atlas 实时迁移](https://learn.mongodb.com/courses/live-migration-with-mongodb-atlas)

## 附加信息
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-additional"></a>

有关更多信息，请参阅 MongoDB 文档中的以下主题：
+ 要将数据移动到无服务器实例，[请使用 Compass 导出和导入数据](https://www.mongodb.com/docs/compass/current/import-export/)，或者使用自管理工具迁移数据。要了解更多信息，请参阅[无服务器实例限制](https://www.mongodb.com/docs/atlas/reference/serverless-instance-limitations/)。
+ 要将数据加载到 Atlas 中的新集群，请参阅[将数据加载到 Atlas](https://www.mongodb.com/docs/atlas/sample-data/#std-label-sample-data)。
+ 要为测试目的复制集群，请参阅[自管理式部署的备份方法](https://www.mongodb.com/docs/manual/core/backups/)。
+ 如果要迁移的应用程序需要近乎持续的正常运行时间，请联系 [MongoDB 支持团队](https://www.mongodb.com/docs/atlas/support/#std-label-request-support)并告知您的正常运行时间要求和集群配置。
+ 有关更多信息，请参阅[迁移或导入数据](https://www.mongodb.com/docs/atlas/import/)。