

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在 上將自我託管的 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*

## 摘要
<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 叢集） 遷移至 中的 MongoDB Atlas 的步驟 AWS 雲端。它使用 [Atlas Live Migration Service](https://www.mongodb.com/cloud/atlas/migrate) 來協助加速從 MongoDB 到 MongoDB Atlas 的資料遷移。

模式隨附於 AWS 上的[遷移至 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-mongodb-atlas/) 指南指南網站上的指南。它提供該指南中討論的其中一個遷移案例的實作步驟。如需其他遷移案例，請參閱 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 Systems Integrator (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 版或更新版本

## Architecture
<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 資料庫遷移至 MongoDB Atlas AWS。當您需要將大型、複雜的資料庫遷移至 MongoDB Atlas 時，請使用此服務，將停機時間和持續資料同步降到最低。此模式使用 Atlas Live Migration Service。

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


下圖顯示 MongoDB 鏡像服務 (`mongomirror`)，您也可以用來 AWS 透過安全[AWS PrivateLink](https://aws.amazon.com/privatelink/)連線將資料從 MongoDB Enterprise Advanced 資料庫和 MongoDB Community 資料庫遷移到 上的 MongoDB Atlas。`mongomirror` 用於內部部署 MongoDB 和 MongoDB Atlas 之間的持續資料複寫。此工具非常適合災難復原或分階段遷移，但超出此模式的範圍。

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


如需支援不同使用案例的更多 MongoDB Atlas 參考架構，請參閱 AWS 《 方案指引》網站上的[遷移至 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-mongodb-atlas/architecture.html)。

## 工具
<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`不需要您關閉現有的複本集或應用程式、不匯入使用者或角色資料，或複製組態資料庫。您可以從 `mongomirror` [MongoDB 文件](https://www.mongodb.com/docs/atlas/import/mongomirror/#download-mongomirror)下載 。

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

如需在 上使用 MongoDB 的最佳實務 AWS，請參閱 [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>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 決定叢集大小。 | 使用來自 的資訊估計工作集大小`db.stats()`，以取得總索引空間。假設經常存取您資料空間的百分比。或者，您可以根據自己的假設來預估記憶體需求。此任務大約需要一週的時間。如需此範例和其他案例的詳細資訊和範例，請參閱[相關資源](#migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-resources)一節。 | DBA、應用程式擁有者 | 
| 估計網路頻寬需求。 | 若要估算您的網路頻寬需求，請將平均文件大小乘以每秒提供的文件數量。請考慮叢集上任何節點所承擔的最大流量。若要計算從叢集到用戶端應用程式的下游資料傳輸率，請使用一段時間內傳回文件總數的總和。如果您的應用程式從次要節點讀取，請將總文件數除以可提供讀取操作的節點數。若要尋找資料庫的平均文件大小，請使用 `db.stats().avgObjSize`命令。此任務通常需要一天的時間。 | DBA | 
| 選取 Atlas 層。 | 遵循 [MongoDB 文件](https://www.mongodb.com/docs/atlas/sizing-tier-selection/)中的指示，選取正確的 Atlas 叢集層。 | DBA | 
| 規劃切換。 | 規劃應用程式切換。 | DBA、應用程式擁有者 | 

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


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 上建立新的 MongoDB Atlas 叢集 AWS。 | 登入 Atlas 並開啟專案的**概觀**頁面。選擇**建立**按鈕來建立叢集。如需詳細資訊，請參閱 [MongoDB 文件](https://www.mongodb.com/docs/atlas/tutorial/deploy-free-tier-cluster/)。 | DBA | 
| 選取 AWS 區域 和 全域叢集組態。 | 從 AWS 區域 Atlas 叢集可用的 清單中選取 。視需要設定全域叢集。如需詳細資訊，請參閱 [MongoDB 文件](https://www.mongodb.com/docs/atlas/tutorial/deploy-free-tier-cluster/#select-your-preferred-region.)。 | DBA | 
| 選取叢集層。 | 選取您偏好的叢集層。您的方案選擇會決定記憶體、儲存體和 IOPS 規格等因素。 | DBA | 
| 設定其他叢集設定。 | 設定其他叢集設定，例如 MongoDB 版本、備份和加密選項。如需這些選項的詳細資訊，請參閱[相關資源](#migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-resources)一節。 | DBA | 

### 設定安全與合規
<a name="configure-security-and-compliance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證和授權使用者。 | 您必須建立和驗證將存取 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)。 | DBA | 
| 建立自訂角色。 | （選用） 在內建 Atlas 資料庫使用者許可未涵蓋您想要的許可集的情況下，Atlas 支援建立自訂角色。 | DBA | 
| 設定 VPC 對等互連。 | （選用） Atlas 支援虛擬[私有雲端 (VPC) 與其他 VPC 對等互連](https://docs.aws.amazon.com/vpc/latest/peering/what-is-vpc-peering.html) AWS。 VPCs  | 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 Data Lake 和靜態加密，請使用 IAM 角色進行身分驗證。 | AWS 管理員 | 
| 使用 設定靜態加密 AWS KMS。 | （選用） Atlas 支援使用 AWS Key Management Service (AWS KMS) 加密儲存引擎和雲端供應商備份。 | AWS 管理員 | 
| 設定用戶端欄位層級加密。 | （選用） Atlas 支援用戶端欄位層級加密，包括欄位的自動加密。 | AWS 管理員 | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 MongoDB Atlas 中選取您的目標複本集。 | 導覽至目的地 Atlas 叢集，然後選擇省略符號 (...) 按鈕。在叢集清單中，此按鈕會出現在叢集名稱下方。在叢集詳細資訊中，按鈕會出現在右側連線****和**組態**按鈕旁。如需詳細資訊，請參閱 [MongoDB 文件](https://www.mongodb.com/docs/atlas/import/c2c-pull-live-migration/#procedure)。 | DBA | 
| 將 Atlas Live Migration Service 新增至存取清單。 | 將 Atlas Live Migration Service 新增至 AWS 來源叢集中的存取清單。這有助於準備來源環境以連線到目標 Atlas 叢集。 | DBA | 
| 使用 Atlas Live Migration Service 執行遷移。 | 選擇**開始遷移**。當**準備切換**按鈕變成綠色時，請執行切換。檢閱 Atlas 叢集效能指標。考慮更新所有應用程式層中的資料庫連線，以指向新的資料庫。 | DBA | 

### 設定操作整合
<a name="configure-operational-integration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 連線至 MongoDB Atlas 叢集。 | 確定 MongoDB Atlas 叢集連線如預期般運作。 | 應用程式擁有者 | 
| 與叢集資料互動。 | 測試叢集資料。 | DBA | 
| 監控您的叢集。 | 確認您的叢集已正確設定。 | DBA | 
| 備份和還原叢集資料。 | 定期排程叢集資料的備份。 | DBA | 

## 疑難排解
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 錯誤：無法連線到指定的來源 | + 請確定您已將正確的子網路範圍新增至來源叢集上的 IP 存取清單。您可以在即時遷移模態視窗中找到四個必要的子網路範圍。<br />+ 確認您指定的主機名稱解析為公有 IP 地址。在命令提示字元中，使用下列其中一個命令：<pre>nslookup <hostname><br />ping <hostname></pre><br />+ 請確定您沒有使用與提取即時遷移不相容的 [VPC 互連連線](https://www.mongodb.com/docs/atlas/security-vpc-peering/)。如果 VPC 互連連線是您唯一的選項，請`mongomirror`改用 。 | 
| 錯誤：無法解析主機名稱 | 找不到指定主機名稱的 IP 地址。確認指定的主機名稱正確且可公開存取。 | 
| 任何其他錯誤 | 如果您遇到任何其他錯誤，請參閱 MongoDB 文件中的[即時遷移 (Pull) 故障診斷](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 Atlas AWS](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 Data Lake](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/)

**在 上設定新的 MongoDB Atlas 環境 ****AWS**
+ [雲端供應商和區域](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 Support](https://www.mongodb.com/docs/atlas/support/#std-label-request-support) 並分享您的執行時間需求和叢集組態。
+ 如需詳細資訊，請參閱[遷移或匯入資料](https://www.mongodb.com/docs/atlas/import/)。