选择网络类型 - ElastiCache 适用于 Redis 的 Amazon
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

选择网络类型

ElastiCache 支持互联网协议版本 4 和 6(IPv4 和 IPv6),允许您将集群配置为接受:

  • 只有 IPv4 连接,

  • 只有 IPv6 连接,

  • 将解为 IPv4 和 IPv6 连接(双堆栈堆栈将解为)

Nitro 系统上构建的所有实例上使用 Redis 引擎版本 6.2 及更高版本的工作负载均支持 IPv6。通过 IPv6 访问 ElastiCache 不额外收费。

注意

不支持迁移在 IPV6 /双栈可用之前创建的集群。也不支持在新创建的集群上切换网络类型。

为网络类型配置子网

如果您在 Amazon VPC 中创建集群,则必须指定一个子网组。ElastiCache 使用该子网组选择与节点关联的子网和子网中的 IP 地址。ElastiCache 集群需要一个双堆栈子网,同时分配 IPv4 和 IPv6 地址才能在双堆栈模式下运行,并需要仅 IPv6 子网才能作为仅 IPv6 运行。

使用双堆栈将解为

在启用集群模式下使用 ElastiCache for Redis 时,从应用程序的角度来看,通过配置端点连接到所有集群节点与直接连接到单个缓存节点没有什么不同。要实现此目的,集群感知客户端必须参与群集发现过程并请求所有节点的配置信息。Redis 的发现协议仅支持每个节点一个 IP。

为了保持与所有现有客户端的向后兼容性,引入了 IP 发现,它允许您在发现协议中选择要通告的 IP 类型(即 IPv4 或 IPv6)。虽然这将auto 发现限制为仅限于一种 IP 类型,但双栈仍然有利于支持集群模式的工作负载,因为它允许在不停机的情况下从 IPv4 迁移(或回滚)到 IPv6 发现 IP 类型。

启用 TLS 的双堆栈 ElastiCache 集群

为 ElastiCache 集群启用 TLS 时,集群发现函数cluster slotscluster shardscluster nodes 将返回主机名而不是 IP。然后使用主机名代替 IP 来连接到 ElastiCache 集群并执行 TLS 握手。这意味着客户端不会受到 IP 发现参数的影响。对于启用 TLS 的集群,IP 发现参数对首选 IP 协议没有影响。相反,使用的 IP 协议将取决于客户端在解析 DNS 主机名时首选的 IP 协议。

有关在解析 DNS 主机名时如何配置 IP 协议首选项的示例,请参阅启用 TLS 的双堆栈 ElastiCache 集群

使用 Amazon Web Services Management Console

使用创建集群时Amazon Web Services Management Console,在 “连接” 下选择一种网络类型,即 IPv4、IPv 6双堆栈。如果您要创建 Redis(已启用集群模式)集群并选择双堆栈,则必须选择发现 IP 类型,即 IPv6 或 IPv4。

有关更多信息,请参阅 创建 Redis(已启用集群模式)集群(控制台)创建 Redis(已禁用集群模式)(控制台)

使用创建复制组时Amazon Web Services Management Console,请选择网络类型,即 IPv4、IPv 6双堆栈。如果您选择双堆栈,则必须选择发现 IP 类型,即 IPv6 或 IPv4。

有关更多信息,请参阅 从头创建 Redis(已禁用集群模式)复制组从头开始在 Redis(已启用集群模式)中创建复制组

使用 CLI

使用 CLI 创建缓存集群时,您可以使用 c reate-cache-cluster 命令并指定NetworkTypeIPDiscovery参数:

对于 Linux、macOS 或 Unix:

aws elasticache create-cache-cluster \ --cache-cluster-id "cluster-test" \ --engine redis \ --cache-node-type cache.m5.large \ --num-cache-nodes 1 \ --network-type dual_stack \ --ip-discovery ipv4

对于 Windows:

aws elasticache create-cache-cluster ^ --cache-cluster-id "cluster-test" ^ --engine redis ^ --cache-node-type cache.m5.large ^ --num-cache-nodes 1 ^ --network-type dual_stack ^ --ip-discovery ipv4

使用 CLI 创建禁用集群模式的复制组时,您可以使用 cre ate-replication-group 命令并指定NetworkTypeIPDiscovery参数:

对于 Linux、macOS 或 Unix:

aws elasticache create-replication-group \ --replication-group-id sample-repl-group \ --replication-group-description "demo cluster with replicas" \ --num-cache-clusters 3 \ --primary-cluster-id redis01 \ --network-type dual_stack \ --ip-discovery ipv4

对于 Windows:

aws elasticache create-replication-group ^ --replication-group-id sample-repl-group ^ --replication-group-description "demo cluster with replicas" ^ --num-cache-clusters 3 ^ --primary-cluster-id redis01 ^ --network-type dual_stack ^ --ip-discovery ipv4

在使用 CLI 创建启用集群模式的复制组并使用 IPv4 进行 IP 发现时,您可以使用 cre ate-replication-group 命令并指定 NetworkTypeIPDiscovery 参数:

对于 Linux、macOS 或 Unix:

aws elasticache create-replication-group \ --replication-group-id demo-cluster \ --replication-group-description "demo cluster" \ --cache-node-type cache.m5.large \ --num-node-groups 2 \ --engine redis \ --cache-subnet-group-name xyz \ --network-type dual_stack \ --ip-discovery ipv4 \ --region us-east-1

对于 Windows:

aws elasticache create-replication-group ^ --replication-group-id demo-cluster ^ --replication-group-description "demo cluster" ^ --cache-node-type cache.m5.large ^ --num-node-groups 2 ^ --engine redis ^ --cache-subnet-group-name xyz ^ --network-type dual_stack ^ --ip-discovery ipv4 ^ --region us-east-1

在使用 CLI 创建启用集群模式的复制组并使用 IPv6 进行 IP 发现时,您可以使用 cre ate-replication-group 命令并指定 NetworkTypeIPDiscovery 参数:

对于 Linux、macOS 或 Unix:

aws elasticache create-replication-group \ --replication-group-id demo-cluster \ --replication-group-description "demo cluster" \ --cache-node-type cache.m5.large \ --num-node-groups 2 \ --engine redis \ --cache-subnet-group-name xyz \ --network-type dual_stack \ --ip-discovery ipv6 \ --region us-east-1

对于 Windows:

aws elasticache create-replication-group ^ --replication-group-id demo-cluster ^ --replication-group-description "demo cluster" ^ --cache-node-type cache.m5.large ^ --num-node-groups 2 ^ --engine redis ^ --cache-subnet-group-name xyz ^ --network-type dual_stack ^ --ip-discovery ipv6 ^ --region us-east-1