

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

# 從頭開始在 Valkey 或 Redis OSS （啟用叢集模式） 中建立複寫群組
<a name="Replication.CreatingReplGroup.NoExistingCluster.Cluster"></a>

您可以使用 ElastiCache 主控台 AWS CLI、 或 ElastiCache API 建立 Valkey 或 Redis OSS （啟用叢集模式） 叢集 (API/CLI：*複寫群組*)。Valkey 或 Redis OSS （啟用叢集模式） 複寫群組具有 1 到 500 個碎片 (API/CLI：節點群組）、每個碎片中的主要節點，以及每個碎片中最多 5 個僅供讀取複本。您可以建立具有較高數量碎片和較低數量複本的叢集，每一叢集最高總計為 90 個節點。此叢集組態的範圍可以從 90 個碎片和 0 個複本到 15 個碎片和 5 個複本，這是允許的複本最大數量。

如果 Valkey 或 Redis OSS 引擎版本為 5.0.6 或更高版本，節點或碎片限制可以提高到每個叢集最多 500 個。例如，您可以選擇設定具有 500 個節點的叢集，並容許碎片在 83 個（每個碎片一個主要版本和 5 個複本）到 500 個（單一主要版本並且沒有複本）之間變化。請確保有足夠的可用 IP 地址來容納增加的數量。常見的缺陷包括子網路群組中的子網路的 CIDR 範圍太小，或是子網路被共用並被其他叢集大量使用。如需詳細資訊，請參閱[建立子網路群組](SubnetGroups.Creating.md)。

 對於 5.0.6 以下的版本，每個叢集的限制為 250 個。

若要請求提高配額，請參閱 [AWS 服務配額](https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html)，並選擇配額類型 **Nodes per cluster per instance type (每執行個體類型每叢集的節點數)**。

**Topics**
+ [使用 ElastiCache 主控台](#Replication.CreatingReplGroup.NoExistingCluster.Cluster.CON)
+ [從頭開始建立 Valkey 或 Redis OSS （啟用叢集模式） 複寫群組 (AWS CLI)](#Replication.CreatingReplGroup.NoExistingCluster.Cluster.CLI)
+ [從頭開始在 Valkey 或 Redis OSS （啟用叢集模式） 中建立複寫群組 (ElastiCache API)](#Replication.CreatingReplGroup.NoExistingCluster.Cluster.API)

## 建立 Valkey 或 Redis OSS （啟用叢集模式） 叢集 （主控台）
<a name="Replication.CreatingReplGroup.NoExistingCluster.Cluster.CON"></a>

若要建立 Valkey 或 Redis OSS （啟用叢集模式） 叢集，請參閱 [建立 Valkey 或 Redis OSS （啟用叢集模式） 叢集 （主控台）](Clusters.Create.md#Clusters.Create.CON.RedisCluster)。請務必啟用叢集模式 (**Cluster Mode enabled (Scale Out) (啟用叢集模式 (向外擴展))**)，並在其中指定至少兩個碎片及一個複本節點。

## 從頭開始建立 Valkey 或 Redis OSS （啟用叢集模式） 複寫群組 (AWS CLI)
<a name="Replication.CreatingReplGroup.NoExistingCluster.Cluster.CLI"></a>

下列程序會使用 建立 Valkey 或 Redis OSS （啟用叢集模式） 複寫群組 AWS CLI。

當您從頭開始建立 Valkey 或 Redis OSS （啟用叢集模式） 複寫群組時，您可以透過對 AWS CLI `create-replication-group` 命令的單一呼叫來建立複寫群組及其所有節點。包含以下參數。

**--replication-group-id**  
您要建立的複寫群組名稱。  
Valkey 或 Redis OSS （啟用叢集模式） 複寫群組命名限制如下：  
+ 必須包含 1-40 個英數字元或連字號。
+ 必須以字母開頭。
+ 不能連續包含兩個連字號。
+ 結尾不能是連字號。

**--replication-group-description**  
複寫群組的說明。

**--cache-node-type**  
複寫群組中每個節點的節點類型。  
ElastiCache 支援以下節點類型。一般而言，最新一代的節點類型跟前一代相同的節點類型比較起來，能夠以較低的成本提供更多記憶體和運算能力。  
如需深入了解每個節點類型的效能詳細資訊，請參閱 [Amazon EC2 執行個體類型](https://aws.amazon.com/ec2/instance-types/)。

**– data-tiering-enabled**  
如果您使用的是 r6gd 節點類型，應設定此參數。如果您不想要資料分層，應設為 `--no-data-tiering-enabled`。如需詳細資訊，請參閱[ElastiCache 中的資料分層](data-tiering.md)。

**--cache-parameter-group**  
指定 `default.redis6.x.cluster.on` 參數群組或衍生自 的參數群組`default.redis6.x.cluster.on`，以建立 Valkey 或 Redis OSS （啟用叢集模式） 複寫群組。如需詳細資訊，請參閱[Redis OSS 6.x 參數變更](ParameterGroups.Engine.md#ParameterGroups.Redis.6-x)。

**--engine**  
redis

**--engine-version**  
3.2.4

**--num-node-groups**  
此複寫群組中節點群組的數量。有效值為 1 到 500。  
節點/碎片的限制可增加至每一叢集 500 個。若要請求增加限制，請參閱 [AWS 服務配額](https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html)，並選取限制類型「每一執行個體類型每一叢集的節點數」。

**--replicas-per-node-group**  
每個節點群組中複本節點的數量。有效值為 0 到 5。

**--網路類型**  
`ipv4`、`ipv` 或 `dual-stack`。若您選擇雙堆疊，則必須將 `--IpDiscovery` 參數設定為 `ipv4` 或 `ipv6`。

若您希望在此複寫群組上啟用傳輸中及待用加密，請新增 `--transit-encryption-enabled` 或 `--at-rest-encryption-enabled` 參數或同時新增兩者，並符合以下條件。
+ 您的複寫群組必須執行 Redis OSS 3.2.6 或 4.0.10 版。
+ 複寫群組必須在 Amazon VPC 中建立。
+ 您也必須包含 `--cache-subnet-group` 參數。
+ 您也必須包含 `--auth-token` 參數，其中包含在此複寫群組上執行操作時所需要 AUTH 字符 (密碼) 的客戶指定字串值。

下列操作會建立`sample-repl-group`具有三個節點群組/碎片 (--num-node-groups) 的 Valkey 或 Redis OSS （啟用叢集模式） 複寫群組，每個群組都有三個節點，一個主要節點和兩個僅供讀取複本 (--replicas-per-node-group)。

若為 Linux、macOS 或 Unix：

```
aws elasticache create-replication-group \
   --replication-group-id sample-repl-group \
   --replication-group-description "Demo cluster with replicas" \
   --num-node-groups 3 \
   --replicas-per-node-group 2 \
   --cache-node-type cache.m4.large \ 
   --engine redis \   
   --security-group-ids SECURITY_GROUP_ID \    
   --cache-subnet-group-name SUBNET_GROUP_NAME>
```

針對 Windows：

```
aws elasticache create-replication-group ^
   --replication-group-id sample-repl-group ^
   --replication-group-description "Demo cluster with replicas" ^
   --num-node-groups 3 ^
   --replicas-per-node-group 2 ^
   --cache-node-type cache.m4.large ^ 
   --engine redis ^   
   --security-group-ids SECURITY_GROUP_ID ^      
   --cache-subnet-group-name SUBNET_GROUP_NAME>
```

上述命令會產生以下輸出。

```
{
    "ReplicationGroup": {
        "Status": "creating", 
        "Description": "Demo cluster with replicas", 
        "ReplicationGroupId": "sample-repl-group", 
        "SnapshotRetentionLimit": 0, 
        "AutomaticFailover": "enabled", 
        "SnapshotWindow": "05:30-06:30", 
        "MemberClusters": [
            "sample-repl-group-0001-001", 
            "sample-repl-group-0001-002", 
            "sample-repl-group-0001-003", 
            "sample-repl-group-0002-001", 
            "sample-repl-group-0002-002", 
            "sample-repl-group-0002-003", 
            "sample-repl-group-0003-001", 
            "sample-repl-group-0003-002", 
            "sample-repl-group-0003-003"
        ], 
        "PendingModifiedValues": {}
    }
}
```

當您從頭開始建立 Valkey 或 Redis OSS （啟用叢集模式） 複寫群組時，您可以使用 `--node-group-configuration` 參數來設定叢集中的每個碎片，如下列設定兩個節點群組 （主控台：碎片） 的範例所示。第一個碎片有兩個節點：一個主要節點及一個僅供讀取複本。第二個碎片有三個節點：一個主要節點及兩個僅供讀取複本。

**--node-group-configuration**  
每個節點群組的組態。`--node-group-configuration` 參數由以下欄位組成。  
+ `PrimaryAvailabilityZone` - 此節點群組主節點所在的可用區域。如果省略此參數，ElastiCache 會為主節點選擇可用區域。

  **範例：**us-west-2a。
+ `ReplicaAvailabilityZones` - 僅供讀取複本所在可用區域的逗點分隔清單。此清單中的可用區域數量必須等於 `ReplicaCount` 的值。如果省略此參數，ElastiCache 會為複本節點選擇可用區域。

  **範例：**"us-west-2a,us-west-2b,us-west-2c"
+ `ReplicaCount` - 此節點群組中複本節點的數量。
+ `Slots` - 指定節點群組 Keyspace 的字串。此字串格式為 `startKey-endKey`。如果省略此參數，ElastiCache 會在節點群組間配置相同的索引鍵。

  **範例：**"0-4999"

   

下列操作會建立`new-group`具有兩個節點群組/碎片 () 的 Valkey 或 Redis OSS （啟用叢集模式） 複寫群組`--num-node-groups`。與上述範例不同，每個節點群組的設定都會與其他節點群組不同 (`--node-group-configuration`)。

若為 Linux、macOS 或 Unix：

```
aws elasticache create-replication-group \
  --replication-group-id new-group \
  --replication-group-description "Sharded replication group" \
  --engine redis \    
  --snapshot-retention-limit 8 \
  --cache-node-type cache.m4.medium \
  --num-node-groups 2 \
  --node-group-configuration \
      "ReplicaCount=1,Slots=0-8999,PrimaryAvailabilityZone='us-east-1c',ReplicaAvailabilityZones='us-east-1b'" \
      "ReplicaCount=2,Slots=9000-16383,PrimaryAvailabilityZone='us-east-1a',ReplicaAvailabilityZones='us-east-1a','us-east-1c'"
```

針對 Windows：

```
aws elasticache create-replication-group ^
  --replication-group-id new-group ^
  --replication-group-description "Sharded replication group" ^
  --engine redis ^    
  --snapshot-retention-limit 8 ^
  --cache-node-type cache.m4.medium ^
  --num-node-groups 2 ^
  --node-group-configuration \
      "ReplicaCount=1,Slots=0-8999,PrimaryAvailabilityZone='us-east-1c',ReplicaAvailabilityZones='us-east-1b'" \
      "ReplicaCount=2,Slots=9000-16383,PrimaryAvailabilityZone='us-east-1a',ReplicaAvailabilityZones='us-east-1a','us-east-1c'"
```

上述操作會產生以下輸出。

```
{
    "ReplicationGroup": {
        "Status": "creating", 
        "Description": "Sharded replication group", 
        "ReplicationGroupId": "rc-rg", 
        "SnapshotRetentionLimit": 8, 
        "AutomaticFailover": "enabled", 
        "SnapshotWindow": "10:00-11:00", 
        "MemberClusters": [
            "rc-rg-0001-001", 
            "rc-rg-0001-002", 
            "rc-rg-0002-001", 
            "rc-rg-0002-002", 
            "rc-rg-0002-003"
        ], 
        "PendingModifiedValues": {}
    }
}
```

如需您可能想要使用的其他資訊和參數，請參閱 AWS CLI 主題 [create-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/create-replication-group.html)。

## 從頭開始在 Valkey 或 Redis OSS （啟用叢集模式） 中建立複寫群組 (ElastiCache API)
<a name="Replication.CreatingReplGroup.NoExistingCluster.Cluster.API"></a>

下列程序會使用 ElastiCache API 建立 Valkey 或 Redis OSS （啟用叢集模式） 複寫群組。

當您從頭開始建立 Valkey 或 Redis OSS （啟用叢集模式） 複寫群組時，您可以透過對 ElastiCache API `CreateReplicationGroup`操作的單一呼叫來建立複寫群組及其所有節點。包含以下參數。

**ReplicationGroupId**  
您要建立的複寫群組名稱。  
Valkey 或 Redis OSS （啟用叢集模式） 複寫群組命名限制如下：  
+ 必須包含 1-40 個英數字元或連字號。
+ 必須以字母開頭。
+ 不能連續包含兩個連字號。
+ 結尾不能是連字號。

**ReplicationGroupDescription**  
複寫群組的說明。

**NumNodeGroups**  
您希望和此複寫群組一同建立的節點群組數量。有效值為 1 到 500。

**ReplicasPerNodeGroup**  
每個節點群組中複本節點的數量。有效值為 1 到 5。

**NodeGroupConfiguration**  
每個節點群組的組態。`NodeGroupConfiguration` 參數由以下欄位組成。  
+ `PrimaryAvailabilityZone` - 此節點群組主節點所在的可用區域。如果省略此參數，ElastiCache 會為主節點選擇可用區域。

  **範例：**us-west-2a。
+ `ReplicaAvailabilityZones` - 僅供讀取複本所在可用區域的清單。此清單中的可用區域數量必須等於 `ReplicaCount` 的值。如果省略此參數，ElastiCache 會為複本節點選擇可用區域。
+ `ReplicaCount` - 此節點群組中複本節點的數量。
+ `Slots` - 指定節點群組 Keyspace 的字串。此字串格式為 `startKey-endKey`。如果省略此參數，ElastiCache 會在節點群組間配置相同的索引鍵。

  **範例：**"0-4999"

   

**CacheNodeType**  
複寫群組中每個節點的節點類型。  
ElastiCache 支援以下節點類型。一般而言，最新一代的節點類型跟前一代相同的節點類型比較起來，能夠以較低的成本提供更多記憶體和運算能力。  
如需深入了解每個節點類型的效能詳細資訊，請參閱 [Amazon EC2 執行個體類型](https://aws.amazon.com/ec2/instance-types/)。

**– data-tiering-enabled**  
如果您使用的是 r6gd 節點類型，應設定此參數。如果您不想要資料分層，應設為 `--no-data-tiering-enabled`。如需詳細資訊，請參閱[ElastiCache 中的資料分層](data-tiering.md)。

**CacheParameterGroup**  
指定 `default.redis6.x.cluster.on` 參數群組或衍生自 的參數群組`default.redis6.x.cluster.on`，以建立 Valkey 或 Redis OSS （啟用叢集模式） 複寫群組。如需詳細資訊，請參閱[Redis OSS 6.x 參數變更](ParameterGroups.Engine.md#ParameterGroups.Redis.6-x)。

**--網路類型**  
`ipv4`、`ipv` 或 `dual-stack`。若您選擇雙堆疊，則必須將 `--IpDiscovery` 參數設定為 `ipv4` 或 `ipv6`。

**引擎**  
redis

**EngineVersion**  
6.0

若您希望在此複寫群組上啟用傳輸中及待用加密，請新增 `TransitEncryptionEnabled=true` 或 `AtRestEncryptionEnabled=true` 參數或同時新增兩者，並符合以下條件。
+ 您的複寫群組必須執行 Redis OSS 3.2.6 或 4.0.10 版。
+ 複寫群組必須在 Amazon VPC 中建立。
+ 您也必須包含 `CacheSubnetGroup` 參數。
+ 您也必須包含 `AuthToken` 參數，其中包含在此複寫群組上執行操作時所需要 AUTH 字符 (密碼) 的客戶指定字串值。

加上分行符號的用意是便於閱讀。

```
https://elasticache.us-west-2.amazonaws.com/
   ?Action=CreateReplicationGroup 
   &CacheNodeType=cache.m4.large
   &CacheParemeterGroup=default.redis6.xcluster.on
   &Engine=redis
   &EngineVersion=6.0
   &NumNodeGroups=3
   &ReplicasPerNodeGroup=2
   &ReplicationGroupDescription=test%20group
   &ReplicationGroupId=myReplGroup
   &Version=2015-02-02
   &SignatureVersion=4
   &SignatureMethod=HmacSHA256
   &Timestamp=20150202T192317Z
   &X-Amz-Credential=<credential>
```

如需其他資訊及您可能需使用的參數，請參閱 ElastiCache API 主題：[CreateReplicationGroup](https://docs.aws.amazon.com/AmazonElastiCache/latest/APIReference/API_CreateReplicationGroup.html)。