我正在运行电子商务应用程序,现在我需要根据 Auto Scaling 配置跨越实例。目前,我正在平衡可用区域中的实例数量。为了更清楚,我在 ap-southeast-1a 中运行 2 个实例,在 ap-southeast-1b 中运行 2 个实例,它们本质上是同质的。
现在我想启用 Auto Scaling 配置,以便跨区域创建相等数量的实例。这样负载均衡器就可以在可用区之间均衡负载。此外,负载减少了相同数量的实例必须在整个区域中关闭。
如何配置自动缩放???
请帮帮我。
我正在运行电子商务应用程序,现在我需要根据 Auto Scaling 配置跨越实例。目前,我正在平衡可用区域中的实例数量。为了更清楚,我在 ap-southeast-1a 中运行 2 个实例,在 ap-southeast-1b 中运行 2 个实例,它们本质上是同质的。
现在我想启用 Auto Scaling 配置,以便跨区域创建相等数量的实例。这样负载均衡器就可以在可用区之间均衡负载。此外,负载减少了相同数量的实例必须在整个区域中关闭。
如何配置自动缩放???
请帮帮我。
您无法设置 Autoscaling 来扩展已存在的实例。您基本上需要在启动配置中重新创建它们,然后让 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-southeast-1a 和 b 的启动配置和 Autoscaling 组。要使用它,您需要做 2 件事中的 1 件事。
要在此 cloudformation 模板中执行此操作,请创建您的 AMI,然后使用新的 AMI ID 编辑此行:
"ap-southeast-1" : { "AMI" : "ami-74dda626" },
最后,要让 autosclaing 正常工作,您需要选择选项 1 或 2,然后运行我发布的 cloudformation 模板。
它将创建一个负载平衡的 4 个实例环境,该环境将分布在 ap-southeast-1 a 和 b