

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

# 設定 Amazon Neptune 全域資料庫
<a name="neptune-gdb-setup"></a>

您可以使用下列其中一種方式建立 Neptune 全球資料庫：
+ [使用所有新的資料庫叢集和執行個體建立全球資料庫](#neptune-gdb-creating-cli)。
+ [使用現有的 Neptune 資料庫叢集作為主要叢集來建立全球資料庫](#neptune-gdb-add-existing)。

**Topics**
+ [Amazon Neptune 中全球資料庫的組態需求](#neptune-gdb-setup-config)
+ [使用 AWS CLI 在 Amazon Neptune 中建立全域資料庫](#neptune-gdb-creating-cli)
+ [將現有的資料庫叢集轉換為全球資料庫](#neptune-gdb-add-existing)
+ [將次要全球資料庫區域新增至 Amazon Neptune 的主要區域](#neptune-gdb-attaching)
+ [連線到全球資料庫](#neptune-gdb-connect)

## Amazon Neptune 中全球資料庫的組態需求
<a name="neptune-gdb-setup-config"></a>

Neptune 全域資料庫至少跨越兩個 AWS 區域。主要 AWS 區域 包含具有一個寫入器執行個體的 Neptune 資料庫叢集。一至五個 AWS 區域 ，每一個都包含完全由僅供讀取複本執行個體組成的唯讀 Neptune 資料庫叢集。至少 AWS 區域 需要一個次要 。

構成全球資料庫的 Neptune 資料庫叢集具有下列特定需求：
+ **資料庫執行個體類別需求** — 全球資料庫需要針對記憶體密集型工作負載最佳化的 `r5` 或 `r6g` 資料庫執行個體類別，例如 `db.r5.large` 執行個體類型。
+ **AWS 區域 需求**   —   全域資料庫需要一個主要 Neptune 資料庫叢集 AWS 區域，以及不同區域中至少一個次要 Neptune 資料庫叢集。您最多可以建立五個次要唯讀 Neptune 資料庫叢集，而且每個叢集必須位於不同的區域。換句話說，Neptune 全球資料庫中沒有兩個 Neptune 資料庫叢集可以在同一個 AWS 區域中。
+ **引擎版本需求** — 全球資料庫中所有資料庫叢集使用的 Neptune 引擎版本應該相同，且必須大於或等於 `1.2.0.0`。如果您在建立新的全球資料庫或叢集或執行個體時未指定引擎版本，則會使用最新的引擎版本。

**重要**  
雖然可以針對全球資料庫中的每個資料庫叢集個別設定資料庫叢集參數群組，但是最好讓叢集之間的設定保持一致，以避免次要叢集必須升級為主要叢集時發生意外的行為變更。例如，在所有資料庫叢集中，對物件索引、串流等使用相同的設定。

## 使用 AWS CLI 在 Amazon Neptune 中建立全域資料庫
<a name="neptune-gdb-creating-cli"></a>

**注意**  
本節中的範例遵循使用反斜線 (`\`) 作為行擴充器字元的 UNIX 慣例。若為 Windows，請將反斜線取代為插入符號 (`^`)。

**使用 建立全域資料庫 AWS CLI**

1. 首先使用 `[create-global-cluster](https://docs.aws.amazon.com/cli/latest/reference/neptune/create-global-cluster.html)` AWS CLI 命令 （包裝 [CreateGlobalCluster](api-global-dbs.md#CreateGlobalCluster) API) 建立空的全域資料庫。指定您要其成為主要的 AWS 區域 名稱、將 Neptune 設定為資料庫引擎，以及選擇性地指定您想要使用的引擎版本 (這必須是 1.2.0.0 版或更高版本)：

   ```
   aws neptune create-global-cluster
     --region (primary region, such as us-east-1) \
     --global-cluster-identifier (ID for the global database) \
     --engine neptune \
     --engine-version (engine version; this is optional)
   ```

1. 全球資料庫可能需要幾分鐘的時間才能使用，因此在進行下一個步驟之前，請使用 `[describe-global-clusters](https://docs.aws.amazon.com/cli/latest/reference/neptune/describe-global-clusters.html)` CLI 命令 (其中包裝 [DescribeGlobalClusters](api-global-dbs.md#DescribeGlobalClusters) API) 來檢查全球資料庫是否可用：

   ```
   aws neptune describe-global-clusters \
     --region (primary region) \
     --global-cluster-identifier (global database ID)
   ```

1. 在 Neptune 全球資料庫變成可用之後，您可以建立新的 Neptune 資料庫叢集成為其主要叢集：

   ```
   aws neptune create-db-cluster \
     --region (primary region) \
     --db-cluster-identifier (ID for the primary DB cluster) \
     --engine neptune \
     --engine-version (engine version; must be >= 1.2.0.0) \
     --global-cluster-identifier (global database ID)
   ```

1. 使用 `[describe-db-clusters](https://docs.aws.amazon.com/cli/latest/reference/neptune/describe-db-clusters.html)` AWS CLI 命令來確認新的資料庫叢集已準備好供您新增其主要資料庫執行個體：

   ```
   aws neptune describe-db-clusters \
     --region (primary region) \
     --db-cluster-identifier (primary DB cluster ID)
   ```

   當回應顯示 `"Status": "available"` 時，請繼續下一個步驟。

1. 使用 `[create-db-instance](https://docs.aws.amazon.com/cli/latest/reference/neptune/create-db-instance.html)` AWS CLI 命令為主要叢集建立主要資料庫執行個體。您必須使用其中一種記憶體最佳化的 `r5` 或 `r6g` 執行個體類型，例如 `db.r5.large`。

   ```
   aws neptune create-db-instance \
     --region (primary region) \
     --db-cluster-identifier (primary cluster ID) \
     --db-instance-class (instance class) \
     --db-instance-identifier (ID for the DB instance) \
     --engine neptune \
     --engine-version (optional: engine version)
   ```

**注意**  
如果您打算使用 Neptune 大量載入器，將資料新增至新的主要資料庫叢集，請在新增次要區域*之前*執行此動作。這比在全球資料庫完全設定之後執行大量載入更快速且更具成本效益。

現在，將一或多個次要區域新增至新的全球資料庫，如 [使用 新增次要區域 AWS CLI](#neptune-gdb-attach-cli) 中所述。

## 將現有的資料庫叢集轉換為全球資料庫
<a name="neptune-gdb-add-existing"></a>

若要將現有資料庫叢集轉換為全域資料庫，請使用 `[create-global-cluster](https://docs.aws.amazon.com/cli/latest/reference/neptune/create-global-cluster.html)` AWS CLI 命令在 AWS 區域 現有資料庫叢集所在的相同 中建立新的全域資料庫，並將其`--source-db-cluster-identifier`參數設定為位於該處之現有叢集的 Amazon Resource Name (ARN)：

```
aws neptune create-global-cluster \
  --region (region where the existing cluster is located) \
  --global-cluster-identifier (provide an ID for the new global database) \
  --source-db-cluster-identifier (the ARN of the existing DB cluster) \
  --engine neptune \
  --engine-version (engine version; this is optional)
```

現在，將一或多個次要區域新增至新的全球資料庫，如 [使用 新增次要區域 AWS CLI](#neptune-gdb-attach-cli) 中所述。

### 使用從快照還原的資料庫叢集作為主要叢集
<a name="neptune-gdb-use-snapshot"></a>

您可以將從快照還原的資料庫叢集轉換為 Neptune 全球資料庫。還原完成後，將其建立的資料庫叢集轉換成新全球資料庫的主要叢集，如上所述。

## 將次要全球資料庫區域新增至 Amazon Neptune 的主要區域
<a name="neptune-gdb-attaching"></a>

Neptune 全域資料庫需要在與主要資料庫叢集 AWS 區域 不同的 中至少有一個次要 Neptune 資料庫叢集。您最多可以將五個次要資料庫叢集附加至主要資料庫叢集。

您新增的每個次要資料庫叢集會將您可在主要叢集上具有的僅供讀取複本執行個體數目上限減一。例如，若有 4 個次要叢集，則您可在主要叢集具有的僅供讀取複本執行個體數目上限為 `15 - 4 = 11`。這表示，如果您在主要資料庫叢集及一個次要叢集中已有 14 個讀取器執行個體，則無法新增另一個次要叢集。

### 使用 AWS CLI 將次要區域新增至 Neptune 中的全域資料庫
<a name="neptune-gdb-attach-cli"></a>

**使用 將次要 AWS 區域 新增至 Neptune 全域資料庫 AWS CLI**

1. 使用 `[create-db-cluster](https://docs.aws.amazon.com/cli/latest/reference/neptune/create-db-cluster.html)` AWS CLI 命令在與主要叢集不同的區域中建立新的資料庫叢集，並設定其`--global-cluster-identifier`參數以指定全域資料庫的 ID：

   ```
   aws neptune create-db-cluster \
     --region (the secondary region) \
     --db-cluster-identifier (ID for the new secondary DB cluster) \
     --global-cluster-identifier (global database ID)
     --engine neptune \
     --engine-version (optional: engine version)
   ```

1. 使用 `[describe-db-clusters](https://docs.aws.amazon.com/cli/latest/reference/neptune/describe-db-clusters.html)` AWS CLI 命令來確認新的資料庫叢集已準備好供您新增其主要資料庫執行個體：

   ```
   aws neptune describe-db-clusters \
     --region (primary region) \
     --db-cluster-identifier (primary DB cluster ID)
   ```

   當回應顯示 `"Status": "available"` 時，請繼續下一個步驟。

1. 使用 `[create-db-instance](https://docs.aws.amazon.com/cli/latest/reference/neptune/create-db-instance.html)` AWS CLI 命令，使用 `r5`或 執行個體類別中的執行個體類型，為主要叢集建立主要資料庫`r6g`執行個體：

   ```
   aws neptune create-db-instance \
     --region (secondary region) \
     --db-cluster-identifier (secondary cluster ID) \
     --db-instance-class (instance class) \
     --db-instance-identifier (ID for the DB instance) \
     --engine neptune \
     --engine-version (optional: engine version)
   ```

**注意**  
如果您不想要在次要區域中提供大量讀取請求，而且主要關心的是能在該處可靠地備份您的資料，則可以建立不含資料庫執行個體的次要資料庫叢集。這樣可以節省費用，因為您只需支付次要叢集的儲存體費用，Neptune 將與主要資料庫叢集中的儲存體保持同步。

## 連線到全球資料庫
<a name="neptune-gdb-connect"></a>

連線到 Neptune 全球資料庫的方式取決於您需要寫入其中還是從中讀取︰
+ 對於唯讀請求或查詢，請連線至 AWS 區域中 Neptune 叢集的讀取器端點。
+ 若要執行變動查詢，請連線至主要資料庫叢集的叢集端點，這可能與您的應用程式 AWS 區域 不同。