首页 文章

AWS cloudformation:如何正确创建redis缓存集群

提问于
浏览
4

我想使用redis创建一个elasticache实例 .

我认为我应该使用它“集群模式禁用”,因为一切都适合一个服务器 . 为了没有SPOF,我想创建一个只读主副本将由AWS推广的只读副本 . 如果可能的话, balancer 主设备和从设备之间的只读操作会很好,但这不是强制性的 .

我使用aws控制台创建了一个正常运行的master / read-replica,然后使用cloudformer创建了一个cloudformation json conf . Cloudformer创建了两个未链接的 AWS::ElastiCache::CacheCluster ,但通过阅读文档 . 我不明白如何链接他们...现在我有这个配置:

{
    "cachehubcache001": {
      "Type": "AWS::ElastiCache::CacheCluster",
      "Properties": {
        "AutoMinorVersionUpgrade": "true",
        "AZMode": "single-az",
        "CacheNodeType": "cache.t2.small",
        "Engine": "redis",
        "EngineVersion": "3.2.4",
        "NumCacheNodes": "1",
        "PreferredAvailabilityZone": { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "Az1B"]},
        "PreferredMaintenanceWindow": "sun:04:00-sun:05:00",
        "CacheSubnetGroupName": {
          "Ref": "cachesubnethubprivatecachesubnetgroup"
        },
        "VpcSecurityGroupIds": [
          {
            "Fn::GetAtt": [
              "sgiHubCacheSG",
              "GroupId"
            ]
          }
        ]
      }
    },
    "cachehubcache002": {
      "Type": "AWS::ElastiCache::CacheCluster",
      "Properties": {
        "AutoMinorVersionUpgrade": "true",
        "AZMode": "single-az",
        "CacheNodeType": "cache.t2.small",
        "Engine": "redis",
        "EngineVersion": "3.2.4",
        "NumCacheNodes": "1",
        "PreferredAvailabilityZone": { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "Az1A"]},
        "PreferredMaintenanceWindow": "sun:02:00-sun:03:00",
        "CacheSubnetGroupName": {
          "Ref": "cachesubnethubprivatecachesubnetgroup"
        },
        "VpcSecurityGroupIds": [
          {
            "Fn::GetAtt": [
              "sgiHubCacheSG",
              "GroupId"
            ]
          }
        ]
      }
    },
}

我知道这是错的,但我无法弄清楚如何创建一个正确的副本 . 我无法理解AWS文档,首先我无法弄清楚我应该使用哪种类型:

由于cloudformer创建了 AWS::ElastiCache::CacheCluster ,我感觉它应该只创建了一个资源,并使用 NumCacheNodes 参数来创建两个资源 .

redis无法使用:

  • NumCacheNodes

  • AZModePreferredAvailabilityZones

所以我不知道如何使这个解决方案多AZ ...

1 回答

  • 3

    我设法使用 AWS::ElastiCache::ReplicationGroupNumCacheClusters 参数提供了拥有众多服务器的可能性 . 注意:似乎你必须自己处理与主/从的连接(但是在主机故障的情况下,aws通常应该检测它并更改从机的dns以允许你指向不改变你的配置) . 这是一个示例:

    "hubElastiCacheReplicationGroup" : {
          "Type" : "AWS::ElastiCache::ReplicationGroup",
          "Properties" : {
            "ReplicationGroupDescription" : "Hub WebServer redis cache cluster",
            "AutomaticFailoverEnabled" : "false",
            "AutoMinorVersionUpgrade" : "true",
            "CacheNodeType" : "cache.t2.small",
            "CacheParameterGroupName" : "default.redis3.2",
            "CacheSubnetGroupName" :  { "Ref": "cachesubnethubprivatecachesubnetgroup" },
            "Engine" : "redis",
            "EngineVersion" : "3.2.4",
            "NumCacheClusters" : { "Ref" : "ElasticacheRedisNumCacheClusters" },
            "PreferredMaintenanceWindow" : "sun:04:00-sun:05:00",
            "SecurityGroupIds" : [ { "Fn::GetAtt": ["sgHubCacheSG",  "GroupId"] } ]
          }
        },
    

相关问题