【问题标题】:AWS cloudformation : how to properly create a redis cache clusterAWS cloudformation:如何正确创建 redis 缓存集群
【发布时间】:2017-11-02 07:05:37
【问题描述】:

我想用redis创建一个elasticache实例。

我认为我应该使用它“禁用集群模式”,因为一切都适合一台服务器。 为了没有 SPOF,我想创建一个只读副本,在主服务器出现故障时由 AWS 提升。 如果可能的话,最好平衡主从之间的只读操作,但这不是强制性的。

我使用 aws 控制台创建了一个正常运行的主/只读副本,然后使用 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

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

【问题讨论】:

    标签: redis amazon-cloudformation amazon-elasticache


    【解决方案1】:

    我设法使用AWS::ElastiCache::ReplicationGroup 做到了这一点,NumCacheClusters 参数提供了拥有大量服务器的可能性。请注意:您似乎必须自己处理与主/从的连接(但在主故障的情况下,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"] } ]
          }
        },
    

    【讨论】:

    • 如何设置名称?
    • 我找到了。是ReplicationGroupId
    猜你喜欢
    • 2020-12-15
    • 2013-03-21
    • 2019-03-02
    • 2018-04-05
    • 2015-08-23
    • 1970-01-01
    • 2019-01-23
    • 2019-11-11
    • 1970-01-01
    相关资源
    最近更新 更多