2013-08-22 60 views
1

我正在运行电子商务应用程序,现在我需要跨越基于自动缩放配置的实例。目前我正在平衡可用区域内的实例数量。为了更清楚地说明,我在ap-southeast-1a中运行了2个实例,在ap-southeast-1b中运行了2个实例,这些实例是同质的。亚马逊网络服务自动扩展可用区域

现在我想启用自动缩放配置,以便在区域间创建等量的实例。这样负载均衡器可以在可用区域之间平衡负载。此外,负载减少了必须在该地区关闭的实例数量相等。

如何配置自动缩放?

请帮助我。

回答

1

您无法设置自动缩放来缩放已存在的实例。您基本上需要在启动配置中重新创建它们,然后让Autoscaling使用该启动配置。这里有一个cloudformation模板:

{ 
    "AWSTemplateFormatVersion" : "2010-09-09", 

    "Description" : "AWS CloudFormation Template to configure chef on an EC2 Instance", 

    "Parameters" : { 
    "KeyName" : { 
     "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance", 
     "Type" : "String" 
    } 
    }, 

    "Mappings" : { 
    "RegionMap" : { 
     "us-east-1"  : { "AMI" : "ami-7f418316" }, 
     "us-west-1"  : { "AMI" : "ami-951945d0" }, 
     "us-west-2"  : { "AMI" : "ami-16fd7026" }, 
     "eu-west-1"  : { "AMI" : "ami-24506250" }, 
     "sa-east-1"  : { "AMI" : "ami-3e3be423" }, 
     "ap-southeast-1" : { "AMI" : "ami-74dda626" }, 
     "ap-northeast-1" : { "AMI" : "ami-dcfa4edd" } 
    } 
    }, 

    "Resources" : { 
    "User" : { 
     "Type" : "AWS::IAM::User", 
     "Properties" : { 
     "Path": "/", 
     "Policies": [{ 
      "PolicyName": "root", 
      "PolicyDocument": { "Statement":[{ 
      "Effect":"Allow", 
      "Action":"*", 
      "Resource":"*" 
      } 
              ]} 
     }] 
     } 
    }, 

    "HostKeys" : { 
     "Type" : "AWS::IAM::AccessKey", 
     "Properties" : { 
     "UserName" : { "Ref": "User" } 
     } 
    }, 
    "ElasticLoadBalancer" : { 
     "Type" : "AWS::ElasticLoadBalancing::LoadBalancer", 
     "Properties" : { 
     "AvailabilityZones" : ["ap-southeast-1a", "ap-southeast-1b"], 
     "Listeners" : [{ 
      "LoadBalancerPort" : "80", 
      "InstancePort" : "8080", 
      "Protocol" : "HTTP" 
     }], 
     "HealthCheck" : { 
      "Target" : "HTTP:8080/jenkins/", 
      "HealthyThreshold" : "3", 
      "UnhealthyThreshold" : "5", 
      "Interval" : "30", 
      "Timeout" : "5" 
     } 
     } 
    }, 

    "WebServerGroup" : { 
     "Type" : "AWS::AutoScaling::AutoScalingGroup", 
     "Properties" : { 
     "AvailabilityZones" : ["ap-southeast-1a", "ap-southeast-1b"], 
     "LoadBalancerNames" : [{"Ref" : "ElasticLoadBalancer"}], 
     "LaunchConfigurationName" : { "Ref" : "LaunchConfig" }, 
     "MinSize" : "1", 
     "MaxSize" : "10", 
     "DesiredCapacity" : "4" 
     } 
    }, 

    "LaunchConfig" : { 
     "Type" : "AWS::AutoScaling::LaunchConfiguration", 

     "Properties" : { 
     "InstanceType" : "m1.small", 
     "KeyName" : { "Ref" : "KeyName" }, 
     "SecurityGroups" : [ {"Ref" : "FrontendGroup"} ], 
     "ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]}, 
     } 
    }, 

    "FrontendGroup" : { 
     "Type" : "AWS::EC2::SecurityGroup", 
     "Properties" : { 
     "GroupDescription" : "Enable SSH and access to Apache and Tomcat", 
     "SecurityGroupIngress" : [ 
      {"IpProtocol" : "tcp", "FromPort" : "8080", "ToPort" : "8080", "CidrIp" : "0.0.0.0/0"}, 
      {"IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0"}, 
      {"IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0"} 
     ] 
     } 
    }, 

    "WaitHandle" : { 
     "Type" : "AWS::CloudFormation::WaitConditionHandle" 
    }, 

    "WaitCondition" : { 
     "Type" : "AWS::CloudFormation::WaitCondition", 
     "DependsOn" : "LaunchConfig", 
     "Properties" : { 
     "Handle" : { "Ref" : "WaitHandle" }, 
     "Timeout" : "1200" 
     } 
    } 
    }, 

    "Outputs" : { 
    } 
} 

此模板将创建启动配置和自动定标组跨越AP-东南-1A和1B。要使用这个,你需要做2件事中的1件。

  1. 创建一个金色AMI,其中包含存储在AMI上的所有应用程序的代码和配置。如果你走这条路线,你需要你的AMI基本上创造一个完全的工作系统,当它推出

要做到这一点这cloudformation模板中,创建您的AMI,然后编辑与新的AMI ID这一行:

"ap-southeast-1" : { "AMI" : "ami-74dda626" }, 
  1. 使用AWS Clouformation init或Chef/puppet/etc编写脚本。这是一个链接:AWS Cloudformation Init。这是首选选项,但您需要大量工作来构建基础架构代码。

最后,为了让自动绘图工作,您需要选择选项1或2,然后运行我发布的cloudformation模板。

它将创建一个负载均衡的4实例环境,将分布在ap-southeast-1和b