如何确定 Redis(已启用集群模式)复制组中的主要端点

How to determine the primary endpoint in Redis (cluster mode enabled) replication groups

我们有一个集群 Redis 设置(引擎版本 5.04),三个节点组每个都在自己的 AZ 中,每个组包含三个节点,在传输和静止时启用加密。 Stunnel 在堡垒主机上配置,这允许我 运行 一个 bash 脚本在需要时(在我们的应用程序升级期间)刷新每个主副本。

通过控制台应用最新的 Redis 软件补丁后,由于自动故障转移,每个节点组中的主要端点都发生了变化,我正在寻找确定新主要端点的最佳方法,所以我的 bash 脚本可以相应更新。

documentation 声明 运行ning aws elasticache describe-replication-groups --replication-group-id my-replication-group 应该表示节点组成员的 CurrentRole e.g.

"NodeGroupMembers": [
   {
      "CurrentRole": "primary", 
      "PreferredAvailabilityZone": "us-west-2a", 
      "CacheNodeId": "0001", 
      "ReadEndpoint": {
         "Port": 6379, 
         "Address": "myreplgroup-001.1abc4d.0001.usw2.cache.amazonaws.com"
      }, 
      "CacheClusterId": "myreplgroup-001"
   }, 
   {
      "CurrentRole": "replica", 
      "PreferredAvailabilityZone": "us-west-2b", 
      "CacheNodeId": "0001", 
      "ReadEndpoint": {
         "Port": 6379, 
         "Address": "myreplgroup-002.1abc4d.0001.usw2.cache.amazonaws.com"
      }, 
      "CacheClusterId": "myreplgroup-002"
   }, 
   {
      ...
   }
]

我对此命令的响应根本不包含 CurrentRole:

"NodeGroupMembers": [
    {
        "PreferredAvailabilityZone": "ap-southeast-2c",
        "CacheNodeId": "0001",
        "CacheClusterId": "my-replication-group-0001-001"
    },
    {
        "PreferredAvailabilityZone": "ap-southeast-2b",
        "CacheNodeId": "0001",
        "CacheClusterId": "my-replication-group-0001-002"
    },
    {
        "PreferredAvailabilityZone": "ap-southeast-2a",
        "CacheNodeId": "0001",
        "CacheClusterId": "my-replication-group-0001-003"
    }
]

是否有可用于确定主要端点的替代 aws cli 命令?通过控制台对主节点进行故障转移很容易,但由于我无法通过 console/cli 确定哪个节点是当前主节点,这意味着猜测需要在我的刷新脚本中定位哪些节点。

我在 Elasticache 的文档中找到 this paragraph

Redis (cluster mode enabled) clusters with replicas, because they have multiple shards (API/CLI: node groups), which mean they also have multiple primary nodes, have a different endpoint structure than Redis (cluster mode disabled) clusters. Redis (cluster mode enabled) has a configuration endpoint which "knows" all the primary and node endpoints in the cluster. Your application connects to the configuration endpoint. Whenever your application writes to or reads from the cluster's configuration endpoint, Redis, behind the scenes, determines which shard the key belongs to and which endpoint in that shard to use. It is all quite transparent to your application.

我猜您提供的示例输出是针对禁用集群模式的复制组的,因为该片段来自与上述相同的文章:

Redis (cluster mode disabled) clusters with replicas have three types of endpoints; the primary endpoint, the reader endpoint and the node endpoints.

我知道这可能是一个有争议的问题(你在 2 年前问过这个问题),但如果你需要刷新集群中的主节点(启用集群模式),只需使用配置端点和更改将传播到每个节点。