

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

# 建立 Amazon Aurora 全域資料庫
<a name="aurora-global-database-creating"></a>

若要使用 AWS 管理主控台、 AWS CLI或 RDS API 建立 Aurora 全域資料庫及其相關資源，請使用下列步驟。

**注意**  
 如果您有現有的 Aurora 資料庫叢集執行全球相容的 Aurora 資料庫引擎，您可以使用此程序的簡短形式。在這種情況下，您可以將另一個 新增至現有的資料庫叢集 AWS 區域 ，以建立 Aurora 全域資料庫。若要這麼做，請參閱[將 AWS 區域 新增至 Amazon Aurora 全域資料庫](aurora-global-database-attaching.md)。

## 主控台
<a name="aurora-global-database-creating.console"></a>

建立 Aurora 全域資料庫的步驟從登入 AWS 區域 支援 Aurora 全域資料庫功能的 開始。如需完整清單，請參閱 [Aurora 全球資料庫的支援區域和資料庫引擎](Concepts.Aurora_Fea_Regions_DB-eng.Feature.GlobalDatabase.md)。

以下其中一個步驟是根據您的 Aurora 資料庫叢集的 Amazon VPC 選擇 Virtual Private Cloud (VPC)。若要使用您自己的 VPC，我們建議您事先建立它，以便您進行選擇。同時，建立任何相關子網路，並視需建立子網路群組和安全群組。若要了解作法，請參閱[教學課程：建立要與資料庫叢集搭配使用的 VPC (僅限 IPv4)](CHAP_Tutorials.WebServerDB.CreateVPC.md)。

如需建立 Aurora 資料庫叢集的一般資訊，請參閱[建立 Amazon Aurora 資料庫叢集](Aurora.CreateInstance.md)。

**建立 Aurora 全域資料庫**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)：// 開啟 Amazon RDS 主控台。

1. 選擇 **Create database** (建立資料庫)。在 **Create database** (建立資料庫) 頁面上，執行下列動作：
   + 若為資料庫建立方法，請選擇 **Standard Create** (標準建立)。(請勿選擇 Easy Create (輕鬆建立)。)
   + 針對**引擎選項**區段的 `Engine type`，請選擇適用的引擎類型：**Aurora (MySQL 相容)** 或 **Aurora (PostgreSQL 相容)**。

1. 使用下列程序中的步驟繼續建立您的 Aurora 全域資料庫。

### 使用 Aurora MySQL 建立全域資料庫
<a name="aurora-global-database.create.console.MySQL"></a>

下列步驟適用於 Aurora MySQL 的所有版本。

**使用 Aurora MySQL 建立 Aurora 全域資料庫**

完成 **Create database** (建立資料庫) 頁面。

1. 對於 **Engine options** (引擎選項)，請選擇下列項目：

   1. 在 **Engine Version** (引擎版本) 中，選擇您要用於 Aurora 全域資料庫的 Aurora MySQL 版本。

1. 在 **Templates** (範本) 中，選擇 **Production** (生產)。或者，如果適合您的應用案例，您可以選擇 Dev/Test (開發/測試)。不要在生產環境中使用開發/測試。

1. 在 **Settings** (設定) 下，執行以下操作：

   1. 為資料庫叢集識別符輸入有意義的名稱。當您完成建立 Aurora 全域資料庫時，此名稱會識別主要資料庫叢集。

   1. 為資料庫執行個體輸入您自己的 `admin` 使用者帳戶密碼，或讓 Aurora 為您產生密碼。如果您選擇自動產生密碼，您會看到複製密碼的選項。  
![建立全域資料庫時 Settings (設定) 選項的螢幕擷取畫面。](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/aurora-global-db-create-ams-3.png)

1. 若為 **DB instance class** (資料庫執行個體類別)，請選擇 `db.r5.large` 或其他記憶體最佳化資料庫執行個體類別。建議您使用 db.r5 或更高版本執行個體類別。

1. 對於 **Availability & durability** (可用性和耐用性)，我們建議您選擇在不同的可用區域 (AZ) 中讓 Aurora 建立 Aurora 複本。如果您現在沒有建立 Aurora 複本，則需要稍後再執行。  
![可用性和耐用性的螢幕擷取畫面。](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/aurora-global-db-create-ams-4b.png)

1. 對於 **Connectivity** (連線)，請根據定義此資料庫執行個體之虛擬聯網環境的 Amazon VPC 選擇 Virtual Private Cloud (VPC)。您可以選擇預設值來簡化此任務。

1. 完成 **Database authentication** (資料庫驗證) 設定。若要簡化程序，您可以立即選擇 **Password authentication** (密碼身分驗證)，稍後再設定 AWS Identity and Access Management (IAM)。

1. 對於 **Additional configuration** (其他設定)，請執行下列動作：

   1. 輸入 **Initial database name** (初始資料庫名稱) 的名稱，以建立此叢集的主要 Aurora 資料庫執行個體。這是 Aurora 主要資料庫叢集的寫入器節點。

      保留為資料庫叢集參數群組和資料庫參數群組選取的預設值，除非您有自己想要使用的自訂參數群組。

   1.  清除 **Enable backtrack** (啟用恢復功能) 核取方塊 (如果已選取)。Aurora 全域資料庫不支援恢復。否則，接受 **Additional configuration** (額外組態) 的其他預設設定。

1. 選擇 **Create database** (建立資料庫)。

   Aurora 完成建立 Aurora 資料庫執行個體、其 Aurora 複本和 Aurora 資料庫叢集的程序可能需要幾分鐘的時間。您可以透過 Aurora 資料庫叢集的狀態，判斷該資料庫叢集已準備好用作 Aurora 全域資料庫中的主要資料庫叢集。如果是這樣，其狀態以及寫入器和複本節點的狀態為 **Available** (可用)，如下所示。  
![Aurora 資料庫叢集準備用於 Aurora 全域資料庫的資料庫螢幕擷取畫面。](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/aurora-global-db-create-ams-5.png)

當您的主要資料庫叢集可用時，請透過向其新增次要叢集來建立 Aurora 全域資料庫。如要執行此操作，請依照 [將 AWS 區域 新增至 Amazon Aurora 全域資料庫](aurora-global-database-attaching.md) 中的步驟進行。

### 使用 Aurora PostgreSQL 建立全域資料庫
<a name="aurora-global-database.create.console.PostgreSQL"></a>

**使用 Aurora PostgreSQL 建立 Aurora 全域資料庫**

完成 **Create database** (建立資料庫) 頁面。

1. 對於 **Engine options** (引擎選項)，請選擇下列項目：

   1. 對於 **Engine Version** (引擎版本)，請選擇您要用於 Aurora 全域資料庫的 Aurora PostgreSQL 版本。

1. 在 **Templates** (範本) 中，選擇 **Production** (生產)。或者，您可以選擇 Dev/Test (開發/測試)。不要在生產環境中使用開發/測試。

1. 在 **Settings** (設定) 下，執行以下操作：

   1. 為資料庫叢集識別符輸入有意義的名稱。當您完成建立 Aurora 全域資料庫時，此名稱會識別主要資料庫叢集。

   1. 為資料庫叢集的預設管理員帳戶輸入您自己的密碼，或讓 Aurora 為您產生密碼。如果您選擇 Auto generate a password (自動產生密碼)，您會看到複製密碼的選項。  
![建立全域資料庫時 Settings (設定) 選項的螢幕擷取畫面。](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/aurora-global-db-create-apg-2.png)

1. 若為 **DB instance class** (資料庫執行個體類別)，請選擇 `db.r5.large` 或其他記憶體最佳化資料庫執行個體類別。建議您使用 db.r5 或更高版本執行個體類別。

1. 針對 **Availability & durability** (可用性和耐用性)，我們建議您選擇在不同的可用區域中讓 Aurora 建立 Aurora 複本。如果您現在沒有建立 Aurora 複本，則需要稍後再執行。

1. 對於 **Connectivity** (連線)，請根據定義此資料庫執行個體之虛擬聯網環境的 Amazon VPC 選擇 Virtual Private Cloud (VPC)。您可以選擇預設值來簡化此任務。

1. (選擇性) 完成 **Database authentication** (資料庫身分驗證) 設定。密碼驗證會一直啟用。若要簡化程序，您可以跳過此部分，稍後再設定 IAM 或密碼和 Kerberos 身分驗證。

1. 對於 **Additional configuration** (其他設定)，請執行下列動作：

   1. 輸入 **Initial database name** (初始資料庫名稱) 的名稱，以建立此叢集的主要 Aurora 資料庫執行個體。這是 Aurora 主要資料庫叢集的寫入器節點。

      保留為資料庫叢集參數群組和資料庫參數群組選取的預設值，除非您有自己想要使用的自訂參數群組。

   1. 接受 **Additional configuration** (其他組態) 的所有其他預設設定，例如加密、日誌匯出等。

1. 選擇 **Create database** (建立資料庫)。

   Aurora 完成建立 Aurora 資料庫執行個體、其 Aurora 複本和 Aurora 資料庫叢集的程序可能需要幾分鐘的時間。當叢集可供使用時，Aurora 資料庫叢集及其寫入器和複本節點都會顯示 **Available** (可用) 狀態。新增次要資料庫叢集之後，這將成為 Aurora 全域資料庫的主要資料庫叢集。  
![Aurora 資料庫叢集準備用於 Aurora 全域資料庫的資料庫螢幕擷取畫面。](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/aurora-global-db-create-apg-5-add-region.png)

當主要資料庫叢集可供使用時，請依照[將 AWS 區域 新增至 Amazon Aurora 全域資料庫](aurora-global-database-attaching.md)中的步驟來建立一或多個次要叢集。

## AWS CLI
<a name="aurora-global-database-creating.cli"></a>

下列程序中的 AWS CLI 命令會完成下列任務：

1. 建立 Aurora 全域資料庫，命名並指定您計劃使用的 Aurora 資料庫引擎類型。

1. 為 Aurora 全域資料庫建立 Aurora 資料庫叢集。

1. 為叢集建立 Aurora 資料庫執行個體。這是全域資料庫的主要 Aurora 資料庫叢集。

1. 為 Aurora 資料庫叢集建立第二個資料庫執行個體。這是完成 Aurora 資料庫叢集的讀取器。

1. 在另一個區域中建立第二個 Aurora 資料庫叢集，然後依照[將 AWS 區域 新增至 Amazon Aurora 全域資料庫](aurora-global-database-attaching.md)中的步驟將其新增至 Aurora 全域資料庫。

遵循您的 Aurora 資料庫引擎的程序。

### 使用 Aurora MySQL 建立全域資料庫
<a name="aurora-serverless.create.cli.MySQL"></a>

**使用 Aurora MySQL 建立 Aurora 全域資料庫**

1. 使用 `[create-global-cluster](https://docs.aws.amazon.com/cli/latest/reference/rds/create-global-cluster.html)` CLI 命令，傳遞 AWS 區域、Aurora 資料庫引擎和版本的名稱。

   針對 Linux、macOS 或 Unix：

   ```
   aws rds create-global-cluster --region {{primary_region}} \
       --global-cluster-identifier {{global_database_id}} \
       --engine aurora-mysql \
       --engine-version {{version}} # optional
   ```

   在 Windows 中：

   ```
   aws rds create-global-cluster ^
       --global-cluster-identifier {{global_database_id}} ^
       --engine aurora-mysql ^
       --engine-version {{version}} # optional
   ```

   這將建立一個「空」的 Aurora 全域資料庫，只有一個名稱 (識別符) 和 Aurora 資料庫引擎。可能需要幾分鐘的時間才能使用 Aurora 全域資料庫。在進行下一個步驟之前，請使用 `[describe-global-clusters](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-global-clusters.html)` CLI 命令來查看它是否可用。

   ```
   aws rds describe-global-clusters --region {{primary_region}} --global-cluster-identifier {{global_database_id}}
   ```

   當 Aurora 全域資料庫可用時，您可以建立其主要 Aurora 資料庫叢集。

1. 若要建立主要 Aurora 資料庫叢集，請使用 `[create-db-cluster](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-cluster.html)` CLI 命令。使用 `--global-cluster-identifier` 參數來包含 Aurora 全球資料庫的名稱。

   對於 Linux、macOS 或 Unix：

   ```
   aws rds create-db-cluster \
     --region {{primary_region}} \
     --db-cluster-identifier {{primary_db_cluster_id}} \
     --master-username {{userid}} \
     --master-user-password {{password}} \
     --engine aurora-mysql \
     --engine-version {{version}} \
     --global-cluster-identifier {{global_database_id}}
   ```

   在 Windows 中：

   ```
   aws rds create-db-cluster ^
     --region {{primary_region}} ^
     --db-cluster-identifier {{primary_db_cluster_id}} ^
     --master-username {{userid}} ^
     --master-user-password {{password}} ^
     --engine aurora-mysql ^
     --engine-version {{version}} ^
     --global-cluster-identifier {{global_database_id}}
   ```

   使用 `[describe-db-clusters](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-clusters.html)` AWS CLI 命令來確認 Aurora 資料庫叢集已就緒。要單出一個特定的 Aurora 資料庫叢集，請使用 `--db-cluster-identifier` 參數。或者，您可以在命令中省略 Aurora 資料庫叢集名稱，以獲取有關給定區域中所有 Aurora 資料庫叢集的詳細資訊。

   ```
   aws rds describe-db-clusters --region {{primary_region}} --db-cluster-identifier {{primary_db_cluster_id}}
   ```

   當叢集的回應顯示 `"Status": "available"` 時，便可以使用。

1. 為主要 Aurora 資料庫叢集建立資料庫執行個體。若要執行這項操作，請使用 `[create-db-instance](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html)` CLI 命令。為您的 Aurora 資料庫叢集命令指定名稱，並指定執行個體的組態詳細資訊。您不需要在命令中傳遞 `--master-username` 和 `--master-user-password` 參數，因為它會從 Aurora 資料庫叢集獲取這些參數。

   若為 `--db-instance-class`，您只能使用那些來自記憶體最佳化類別，例如 `db.r5.large`。建議您使用 db.r5 或更高版本執行個體類別。如需這些類別的相關資訊，請參閱 [資料庫執行個體類別的類型](Concepts.DBInstanceClass.Types.md)。

   對於 Linux、macOS 或 Unix：

   ```
   aws rds create-db-instance \
     --db-cluster-identifier {{primary_db_cluster_id}} \
     --db-instance-class {{instance_class}} \
     --db-instance-identifier {{db_instance_id}} \
     --engine aurora-mysql \
     --engine-version {{version}} \
     --region {{primary_region}}
   ```

   在 Windows 中：

   ```
   aws rds create-db-instance ^
     --db-cluster-identifier {{primary_db_cluster_id}} ^
     --db-instance-class {{instance_class}} ^
     --db-instance-identifier {{db_instance_id}} ^
     --engine aurora-mysql ^
     --engine-version {{version}} ^
     --region {{primary_region}}
   ```

    `create-db-instance` 作業可能需要一些時間才能完成。在繼續之前，請檢查狀態以查看 Aurora 資料庫執行個體是否可用。

   ```
   aws rds describe-db-clusters --db-cluster-identifier {{primary_db_cluster_id}}
   ```

    當命令傳回 `available` 的狀態時，您可以為主要資料庫叢集建立另一個 Aurora 資料庫執行個體。這是 Aurora 資料庫叢集的讀取器執行個體 (Aurora 複本)。

1.  若要為叢集建立另一個 Aurora 資料庫執行個體，請使用 `[create-db-instance](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html)` CLI 命令。

   對於 Linux、macOS 或 Unix：

   ```
   aws rds create-db-instance \
     --db-cluster-identifier {{primary_db_cluster_id}} \
     --db-instance-class {{instance_class}} \
     --db-instance-identifier {{replica_db_instance_id}} \
     --engine aurora-mysql
   ```

   在 Windows 中：

   ```
   aws rds create-db-instance ^
     --db-cluster-identifier {{primary_db_cluster_id}} ^
     --db-instance-class {{instance_class}} ^
     --db-instance-identifier {{replica_db_instance_id}} ^
     --engine aurora-mysql
   ```

 當資料庫執行個體可用時，會從寫入器節點開始複寫到複本。繼續之前，請檢查資料庫執行個體是否可以使用 `[describe-db-instances](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-instances.html)` CLI 命令。

 此時，您有一個 Aurora 全域資料庫，其主要 Aurora 資料庫叢集包含寫入器資料庫執行個體和 Aurora 複本。您現在可以在不同區域中新增唯讀 Aurora 資料庫叢集，以完成 Aurora 全域資料庫。若要啟用，請依照「[將 AWS 區域 新增至 Amazon Aurora 全域資料庫](aurora-global-database-attaching.md)」中的步驟進行。

### 使用 Aurora PostgreSQL 建立全域資料庫
<a name="aurora-serverless.create.cli.PostgreSQL"></a>

 當您使用下列命令建立 Aurora 全域資料庫的 Aurora 物件時，每個命令可能需要幾分鐘的時間才能使用。我們建議您在完成任何命令之後，檢查特定 Aurora 物件的狀態，以確定狀態可用。

 若要執行這項操作，請使用 `[describe-global-clusters](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-global-clusters.html)` CLI 命令。

```
aws rds describe-global-clusters --region {{primary_region}}
    --global-cluster-identifier {{global_database_id}}
```

**使用 Aurora PostgreSQL建立 Aurora 全域資料庫**

1. 使用 `[create-global-cluster](https://docs.aws.amazon.com/cli/latest/reference/rds/create-global-cluster.html)` CLI 命令。

   對於 Linux、macOS 或 Unix：

   ```
   aws rds create-global-cluster --region {{primary_region}} \
       --global-cluster-identifier {{global_database_id}} \
       --engine aurora-postgresql \
       --engine-version {{version}} # optional
   ```

   在 Windows 中：

   ```
   aws rds create-global-cluster ^
       --global-cluster-identifier {{global_database_id}} ^
       --engine aurora-postgresql ^
       --engine-version {{version}} # optional
   ```

   當 Aurora 全域資料庫可用時，您可以建立其主要 Aurora 資料庫叢集。

1.  若要建立主要 Aurora 資料庫叢集，請使用 `[create-db-cluster](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-cluster.html)` CLI 命令。使用 `--global-cluster-identifier` 參數來包含 Aurora 全球資料庫的名稱。

   對於 Linux、macOS 或 Unix：

   ```
   aws rds create-db-cluster \
     --region {{primary_region}} \
     --db-cluster-identifier {{primary_db_cluster_id}} \
     --master-username {{userid}} \
     --master-user-password {{password}} \
     --engine aurora-postgresql \
     --engine-version {{version}} \
     --global-cluster-identifier {{global_database_id}}
   ```

   在 Windows 中：

   ```
   aws rds create-db-cluster ^
     --region {{primary_region}} ^
     --db-cluster-identifier {{primary_db_cluster_id}} ^
     --master-username {{userid}} ^
     --master-user-password {{password}} ^
     --engine aurora-postgresql ^
     --engine-version {{version}} ^
     --global-cluster-identifier {{global_database_id}}
   ```

   檢查 Aurora 資料庫叢集是否已準備就緒。當下列命令的回應為 Aurora 資料庫叢集顯示 `"Status": "available"` 時，您可以繼續執行。

   ```
   aws rds describe-db-clusters --region {{primary_region}} --db-cluster-identifier {{primary_db_cluster_id}}
   ```

1. 為主要 Aurora 資料庫叢集建立資料庫執行個體。若要執行這項操作，請使用 `[create-db-instance](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html)` CLI 命令。

   使用 `--db-cluster-identifier` 參數傳遞 Aurora 資料庫叢集的名稱。

   您不需要在命令中傳遞 `--master-username` 和 `--master-user-password` 參數，因為它會從 Aurora 資料庫叢集獲取這些參數。

   若為 `--db-instance-class`，您只能使用那些來自記憶體最佳化類別，例如 `db.r5.large`。建議您使用 db.r5 或更高版本執行個體類別。如需這些類別的相關資訊，請參閱 [資料庫執行個體類別的類型](Concepts.DBInstanceClass.Types.md)。

   對於 Linux、macOS 或 Unix：

   ```
   aws rds create-db-instance \
     --db-cluster-identifier {{primary_db_cluster_id}} \
     --db-instance-class {{instance_class}} \
     --db-instance-identifier {{db_instance_id}} \
     --engine aurora-postgresql \
     --engine-version {{version}} \
     --region {{primary_region}}
   ```

   在 Windows 中：

   ```
   aws rds create-db-instance ^
     --db-cluster-identifier {{primary_db_cluster_id}} ^
     --db-instance-class {{instance_class}} ^
     --db-instance-identifier {{db_instance_id}} ^
     --engine aurora-postgresql ^
     --engine-version {{version}} ^
     --region {{primary_region}}
   ```

1.  請先檢查 Aurora 資料庫執行個體的狀態，然後再繼續。

   ```
   aws rds describe-db-clusters --db-cluster-identifier {{primary_db_cluster_id}}
   ```

    如果回應顯示 Aurora 資料庫執行個體狀態為 `available`，您可以為主要資料庫叢集建立另一個 Aurora 資料庫執行個體。

1.  若要建立 Aurora 資料庫叢集的 Aurora 複本，請使用 `[create-db-instance](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html)` CLI 命令。

   對於 Linux、macOS 或 Unix：

   ```
   aws rds create-db-instance \
     --db-cluster-identifier {{primary_db_cluster_id}} \
     --db-instance-class {{instance_class}} \
     --db-instance-identifier {{replica_db_instance_id}} \
     --engine aurora-postgresql
   ```

   在 Windows 中：

   ```
   aws rds create-db-instance ^
     --db-cluster-identifier {{primary_db_cluster_id}} ^
     --db-instance-class {{instance_class}} ^
     --db-instance-identifier {{replica_db_instance_id}} ^
     --engine aurora-postgresql
   ```

 當資料庫執行個體可用時，會從寫入器節點開始複寫到複本。繼續之前，請檢查資料庫執行個體是否可以使用 `[describe-db-instances](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-instances.html)` CLI 命令。

您的 Aurora 全域資料庫存在，但它只有其主要區域，其中包含由寫入器資料庫執行個體和 Aurora 複本所組成的 Aurora 資料庫叢集。您現在可以在不同區域中新增唯讀 Aurora 資料庫叢集，以完成 Aurora 全域資料庫。若要啟用，請依照「[將 AWS 區域 新增至 Amazon Aurora 全域資料庫](aurora-global-database-attaching.md)」中的步驟進行。

## RDS API
<a name="aurora-global-database-creating.api"></a>

 若要以 RDS API 建立 Aurora 全球資料庫，請執行 [CreateGlobalCluster](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateGlobalCluster.html) 操作。