

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用全局数据存储 (CLI)
<a name="Redis-Global-Datastores-CLI"></a>

您可以使用 AWS Command Line Interface (AWS CLI) 从命令行管理多个 AWS 服务并通过脚本自动执行这些服务。您可以使用 AWS CLI 执行临时（一次性）操作。

## 下载和配置 AWS CLI
<a name="Redis-Global-Datastores-Downloading-CLI"></a>

AWS CLI 在 Windows、macOS 或 Linux 上运行。按照以下步骤下载和并对其进行配置。

**下载、安装和配置 CLI**

1. 在 [AWS Command Line Interface](https://aws.amazon.com/cli) 网页上下载 AWS CLI。

1. 按照 *AWS Command Line Interface 用户指南*中的说明安装 AWS CLI 和配置 AWS CLI。

## 将 AWS CLI 与全局数据存储结合使用
<a name="Redis-Global-Datastores-Using-CLI"></a>

使用以下 CLI 操作来处理全局数据存储：
+ [create-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/create-global-replication-group.html)

  ```
  aws elasticache create-global-replication-group \
     --global-replication-group-id-suffix my global datastore  \
     --primary-replication-group-id sample-repl-group  \
     --global-replication-group-description an optional description of the global datastore
  ```

  Amazon ElastiCache 会在全局数据存储 ID 被创建时自动对其应用前缀。每个 AWS 区域有自己的前缀。例如，在美国西部（北加利福尼亚）区域创建的全局数据存储 ID 以“virxk”和您提供的后缀名称开头。后缀与自动生成的前缀相结合，保证了全局数据存储名称在多个区域中的唯一性。

  下表列出了每个 AWS 区域及其全局数据存储 ID 前缀。

    
****    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/AmazonElastiCache/latest/dg/Redis-Global-Datastores-CLI.html)
+  [create-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/create-replication-group.html) – 使用此操作可通过向 `--global-replication-group-id` 参数提供全局数据存储的名称来创建全局数据存储的辅助集群。

  ```
  aws elasticache create-replication-group \
    --replication-group-id secondary replication group name \
    --replication-group-description “Replication group description" \
    --global-replication-group-id global datastore name
  ```

  当调用此操作并传入 `--global-replication-group-id` 值时，ElastiCache 会从全局复制组的主复制组中推断下列参数的值。请勿传入这些参数的值：

  `"PrimaryClusterId",`

  `"AutomaticFailoverEnabled",`

  ` "NumNodeGroups",`

  ` "CacheParameterGroupName",`

  ` "CacheNodeType",`

  ` "Engine",`

  ` "EngineVersion",`

  ` "CacheSecurityGroupNames",`

  ` "EnableTransitEncryption",`

  ` "AtRestEncryptionEnabled",`

  ` "SnapshotArns",`

  ` "SnapshotName"`
+ [describe-global-replication-groups](https://docs.aws.amazon.com/cli/latest/reference/elasticache/describe-global-replication-groups.html)

  ```
  aws elasticache describe-global-replication-groups \
     --global-replication-group-id my global datastore  \
     --show-member-info an optional parameter that returns a list of the primary and secondary clusters that make up the global datastore
  ```
+ [modify-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/modify-global-replication-group.html)

  ```
  aws elasticache modify-global-replication-group \
     --global-replication-group-id my global datastore  \
     --automatic-failover-enabled \
     --cache-node-type node type \
     --cache-parameter-group-name parameter group name \ 
     --engine-version engine version \
     -—apply-immediately \
     --global-replication-group-description description
  ```

  **ElastiCache GlobalDataStore 的 Redis 到 OSS Valkey 跨引擎升级**

  您可以使用控制台、API 或 CLI 将现有 Redis OSS 全局复制组升级到 Valkey。

  如果您有现成的 Redis OSS 全局复制组，您可以使用 modify-global-replication-group API 指定新引擎和引擎版本，从而升级到 Valkey。

  对于 Linux、macOS 或 Unix：

  ```
  aws elasticache modify-global-replication-group \
     --global-replication-group-id myGlobalReplGroup \
     --engine valkey \
     --apply-immediately \
     --engine-version 8.0
  ```

  对于 Windows：

  ```
  aws elasticache modify-global-replication-group ^
     --global-replication-group-id myGlobalReplGroup ^
     --engine valkey ^
     --apply-immediately ^
     --engine-version 8.0
  ```

  如果您对要升级的现有 Redis OSS 全局复制组应用了自定义缓存参数组，则还需要在请求中传递自定义 Valkey 缓存参数组。输入 Valkey 自定义参数组必须具有与现有 Redis OSS 自定义参数组相同的 Redis OSS 静态参数值。

  对于 Linux、macOS 或 Unix：

  ```
  aws elasticache modify-global-replication-group \
     --global-replication-group-id myGlobalReplGroup \
     --engine valkey \
     --engine-version 8.0 \
     --apply-immediately \
     --cache-parameter-group-name myParamGroup
  ```

  对于 Windows：

  ```
  aws elasticache modify-global-replication-group ^
     --global-replication-group-id myGlobalReplGroup ^
     --engine valkey ^
     --engine-version 8.0 ^
     --apply-immediately ^
     --cache-parameter-group-name myParamGroup
  ```
+ [delete-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/delete-global-replication-group.html)

  ```
  aws elasticache delete-global-replication-group \
     --global-replication-group-id my global datastore  \
     --retain-primary-replication-group defaults to true
  ```
+ [disassociate-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/disassociate-global-replication-group.html)

  ```
  aws elasticache disassociate-global-replication-group \
     --global-replication-group-id my global datastore  \
     --replication-group-id my secondary cluster  \
     --replication-group-region the AWS Region in which the secondary cluster resides
  ```
+ [failover-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/failover-global-replication-group.html)

  ```
  aws elasticache failover-replication-group \
     --global-replication-group-id my global datastore \
     --primary-region The AWS Region of the primary cluster \  
     --primary-replication-group-id  The name of the global datastore, including the suffix.
  ```
+ [increase-node-groups-in-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/increase-node-groups-in-global-replication-group.html)

  ```
  aws elasticache increase-node-groups-in-global-replication-group \
     --apply-immediately yes \
     --global-replication-group-id global-replication-group-name \
     --node-group-count 3
  ```
+ [decrease-node-groups-in-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/decrease-node-groups-in-global-replication-group.html)

  ```
  aws elasticache decrease-node-groups-in-global-replication-group \
     --apply-immediately yes \
     --global-replication-group-id global-replication-group-name \
     --node-group-count 3
  ```
+ [rebalance-shards-in-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/rebalance-slots-in-global-replication-group.html)

  ```
  aws elasticache rebalance-shards-in-global-replication-group \
     --apply-immediately yes \
     --global-replication-group-id global-replication-group-name
  ```

使用 help 列出 ElastiCache for Valkey 或 ElastiCache for Redis OSS 的所有可用命令。

```
aws elasticache help
```

您还可以使用帮助来描述特定命令并了解有关其用法的详细信息：

```
aws elasticache create-global-replication-group help
```