

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

# 使用應用程式復原控制器管理 EMR 叢集的多可用區域容錯移轉
<a name="multi-az-failover-spark-emr-clusters-arc"></a>

*Aarti Rajput、Ashish Bhatt、Neeti Mishra 和 Nidhi Sharma，Amazon Web Services*

## 摘要
<a name="multi-az-failover-spark-emr-clusters-arc-summary"></a>

此模式為 Amazon EMR 工作負載提供有效的災難復原策略，以協助確保單一區域內多個可用區域的高可用性和資料一致性 AWS 區域。此設計使用 [Amazon Application Recovery Controller](https://docs.aws.amazon.com/r53recovery/latest/dg/what-is-route53-recovery.html) 和 [Application Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html) 來管理 Apache Spark 型 EMR 叢集的容錯移轉操作和流量分佈。

在標準條件下，主要可用區域會託管具有完整讀取/寫入功能的作用中 EMR 叢集和應用程式。如果可用區域意外故障，流量會自動重新導向至次要可用區域，其中會啟動新的 EMR 叢集。兩個可用區域都透過專用[閘道端點](https://docs.aws.amazon.com/vpc/latest/privatelink/vpc-endpoints-s3.html)存取共用的 Amazon Simple Storage Service (Amazon S3) 儲存貯體，以確保一致的資料管理。此方法可將停機時間降至最低，並在可用區域故障期間快速復原關鍵大數據工作負載。此解決方案適用於金融或零售等產業，其中即時分析至關重要。

## 先決條件和限制
<a name="multi-az-failover-spark-emr-clusters-arc-prereqs"></a>

**先決條件**
+ 作用中 [AWS 帳戶](https://aws.amazon.com/resources/create-account/)
+ [Amazon Elastic Compute Cloud (Amazon EC2) 上的 Amazon EMR](https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-what-is-emr.html) Amazon EC2
+ 從 EMR 叢集的主節點存取 Amazon S3。
+ AWS 多可用區域基礎設施

**限制**
+ 有些 AWS 服務 完全無法使用 AWS 區域。如需區域可用性，請參閱[AWS 服務 依區域](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)頁面，然後選擇服務的連結。

**產品版本**
+ [Amazon EMR 6.x 和更新版本](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-release-components.html)

## Architecture
<a name="multi-az-failover-spark-emr-clusters-arc-architecture"></a>

**目標技術堆疊**
+ Amazon EMR 叢集
+ Amazon 應用程式復原控制器說明
+ Application Load Balancer
+ Amazon S3 儲存貯體
+ Amazon S3 閘道端點

**目標架構**

![\[使用 Application Recovery Cotnroller 的自動化復原機制架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/e5ecdb66-0eef-4a6a-8367-982a55104748/images/e982d580-13db-4bdd-9f6b-6400d7c31c01.png)


此架構使用多個可用區域並透過應用程式復原控制器實作自動化復原機制，以提供應用程式彈性。

1. Application Load Balancer 會將流量路由到作用中的 Amazon EMR 環境，通常是主要可用區域中的主要 EMR 叢集。

1. 作用中的 EMR 叢集會處理應用程式請求，並透過專用 Amazon S3 閘道端點連線至 Amazon S3，以進行讀取和寫入操作。

1. Amazon S3 做為中央資料儲存庫，可能用作檢查點或 EMR 叢集之間的共用儲存。當 EMR 叢集透過`s3://`通訊協定和 [EMR 檔案系統 (EMRFS)](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-fs.html) 直接寫入 Amazon S3 時，會維持資料一致性。

1. 應用程式復原控制器會持續監控主要可用區域的運作狀態，並視需要自動管理容錯移轉操作。

1. 如果應用程式復原控制器偵測到主要 EMR 叢集失敗，則會採取下列動作：
   + 在可用區域 2 中啟動次要 EMR 叢集的容錯移轉程序。
   + 更新路由組態，將流量導向次要叢集。

## 工具
<a name="multi-az-failover-spark-emr-clusters-arc-tools"></a>

**AWS 服務**
+ [Amazon Application Recovery Controller](https://docs.aws.amazon.com/r53recovery/latest/dg/what-is-route53-recovery.html)** **可協助您管理和協調跨 和 AWS 區域 可用區域的應用程式復原。此服務透過減少傳統工具和程序所需的手動步驟，簡化程序並改善應用程式復原的可靠性。
+ [Application Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html) 在應用程式層操作，這是開放系統互連 (OSI) 模型的第七層。它將傳入的應用程式流量分散到多個可用區域中的多個目標，例如 EC2 執行個體。這會提高您應用程式的可用性。
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) 是一種開放原始碼工具，可協助您 AWS 服務 透過命令列 shell 中的命令與 互動。
+ [Amazon EMR](https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-what-is-emr.html) 是一種大數據平台，可為 Apache Spark、Apache Hive 和 Presto 等開放原始碼架構提供資料處理、互動式分析和機器學習。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 提供簡單的 Web 服務介面，可讓您隨時從任何地方存放和擷取任意數量的資料。使用此服務，您可以輕鬆建置利用雲端原生儲存的應用程式。
+ [Amazon S3 的閘道端點](https://docs.aws.amazon.com/vpc/latest/privatelink/vpc-endpoints-s3.html)是您在路由表中指定的閘道，可透過 AWS 網路從虛擬私有雲端 (VPC) 存取 Amazon S3。

## 最佳實務
<a name="multi-az-failover-spark-emr-clusters-arc-best-practices"></a>
+ 遵循[AWS 安全性、身分和合規性的最佳實務](https://aws.amazon.com/architecture/security-identity-compliance/?cards-all.sort-by=%5b…%5d.sort-order=desc&awsf.content-type=*all&awsf.methodology=*all)，以確保強大且安全的架構。
+ 將架構與 [AWS Well-Architected Framework 對齊。](https://aws.amazon.com/architecture/well-architected/)
+ 使用 Amazon S3 Access Grants 來管理從 Spark 型 EMR 叢集到 Amazon S3 的存取權。如需詳細資訊，請參閱部落格文章[使用 Amazon EMR 搭配 S3 存取授權擴展 Amazon S3 的 Spark 存取](https://aws.amazon.com/blogs/big-data/use-amazon-emr-with-s3-access-grants-to-scale-spark-access-to-amazon-s3/)。
+ [使用 Amazon S3 改善 Spark 效能](https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-spark-s3-performance.html)。

## 史詩
<a name="multi-az-failover-spark-emr-clusters-arc-epics"></a>

### 設定您的環境
<a name="set-up-your-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 登入 AWS 管理主控台。 | 以 IAM 使用者[AWS 管理主控台](https://console.aws.amazon.com/)身分登入 。如需說明，請參閱 [AWS 文件](https://docs.aws.amazon.com/signin/latest/userguide/introduction-to-iam-user-sign-in-tutorial.html)。 | AWS DevOps | 
| 設定 AWS CLI。** ** | 安裝 AWS CLI 或將其更新至最新版本，以便在 AWS 服務 中與 互動 AWS 管理主控台。如需說明，請參閱 [AWS CLI 文件](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。 | AWS DevOps | 

### 在 EMR 叢集上部署 Spark 應用程式
<a name="deploy-a-spark-application-on-your-emr-cluster"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 S3 儲存貯體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/multi-az-failover-spark-emr-clusters-arc.html) | AWS DevOps | 
| 建立 EMR 叢集。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/multi-az-failover-spark-emr-clusters-arc.html) | AWS DevOps | 
| 設定 EMR 叢集的安全設定。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/multi-az-failover-spark-emr-clusters-arc.html) | AWS DevOps | 
| 連線至 EMR 叢集。 | 使用提供的金鑰對，透過 SSH 連線至 EMR 叢集的主節點。請確定金鑰對檔案與您的應用程式位於相同的目錄中。執行下列命令來設定金鑰對的正確許可，並建立 SSH 連線：<pre>chmod 400 <key-pair-name><br />ssh -i ./<key-pair-name> hadoop@<master-node-public-dns></pre> | AWS DevOps | 
| 部署 Spark 應用程式。 | 建立 SSH 連線後，您會在 Hadoop 主控台中。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/multi-az-failover-spark-emr-clusters-arc.html) | AWS DevOps | 
| 監控 Spark 應用程式。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/multi-az-failover-spark-emr-clusters-arc.html) | AWS DevOps | 

### 將流量轉移到另一個可用區域
<a name="shift-traffic-to-another-availability-zone"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Application Load Balancer。 | 設定目標群組，在 內跨兩個可用區域部署的 Amazon EMR 主節點之間路由流量 AWS 區域。如需說明，請參閱 Elastic Load Balancing [ Load Balancing 文件中的為 Application Load Balancer 建立目標群組](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-target-group.html)。 | AWS DevOps | 
| 在應用程式復原控制器中設定區域轉移。 | 在此步驟中，您將使用應用程式復原控制器中的[區域轉移功能](https://docs.aws.amazon.com/r53recovery/latest/dg/arc-zonal-shift.html)，將流量轉移到另一個可用區域。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/multi-az-failover-spark-emr-clusters-arc.html)若要使用 AWS CLI，請參閱應用程式復原控制器文件中[使用 AWS CLI 搭配區域轉移的範例](https://docs.aws.amazon.com/r53recovery/latest/dg/getting-started-cli-zonalshift.html)。 | AWS DevOps | 
| 驗證區域轉移組態和進度。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/multi-az-failover-spark-emr-clusters-arc.html) | AWS DevOps | 

## 相關資源
<a name="multi-az-failover-spark-emr-clusters-arc-resources"></a>
+ AWS CLI 命令：
  + [create-cluster](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/emr/create-cluster.html)
  + [describe-cluster](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/emr/describe-cluster.html)
  + [arc-zonal-shift](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/arc-zonal-shift/index.html)
+ [設定 Spot 執行個體的 Amazon EMR 叢集執行個體類型和最佳實務](https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-plan-instances-guidelines.html) (Amazon EMR 文件）
+ [IAM 中的安全最佳實務 ](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)(IAM 文件）
+ [使用執行個體描述檔](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html) (IAM 文件）
+ [在 ARC 中使用區域轉移和區域自動轉移來復原應用程式 ](https://docs.aws.amazon.com/r53recovery/latest/dg/multi-az.html)（應用程式復原控制器文件）