Amazon VPC 的 CloudFormation 示例模板

下面的 CloudFormation 模板可用于启动 Amazon 虚拟私有云 (VPC) 中的高可用性 ArcGIS Server 堆栈。请参阅 AWS Cloud Formation 和 ArcGIS Server 的高可用性

复制此代码,将其粘贴到文本文件并根据需要进行调整。之后,在使用 CloudFormation 创建 ArcGIS Server 堆栈时浏览到此文本文件。

本主题包含以下内容:

模板代码

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

	"Description": "CloudFormation template to launch a highly available ArcGIS Server stack in Amazon VPC",

	"Parameters" : {
		"AMI" : {
			"Description" : "Your ArcGIS Server AMI ID.",
			"Type" : "String"
		},
		"VpcId" : {
			"Type" : "String",
			"Description" : "VpcId of your existing Virtual Private Cloud (VPC).",
			"Default" : "vpc-4adfc123"
		},
		"Subnets" : {
			"Type" : "CommaDelimitedList",
			"Default" : "subnet-8ec5b8e6,subnet-1edcc277",
			"Description" : "The list of SubnetIds where the stack will be launched"
		},
	    "AZs" : {
		"Type" : "CommaDelimitedList",
		"Default" : "us-west-2b,us-west-2c",
		"Description" : "The list of AvailabilityZones for your Virtual Private Cloud (VPC). It needs to be consistent with the AZ of your subnets."
		},
		"InstanceType" : {
			"Description" : "Type of EC2 instance to launch.",
			"Type" : "String",
			"Default" : "m1.medium",
			"AllowedValues" : [ "m1.medium","m1.large","m1.xlarge","m2.xlarge","m2.2xlarge","m2.4xlarge","m3.xlarge","m3.2xlarge","c1.xlarge","cc2.8xlarge","cg1.4xlarge", "cr1.8xlarge","hi1.4xlarge","hs1.8xlarge"],
			"ConstraintDescription" : "must be a valid EC2 instance type."			
		},
		"KeyName" : {
			"Description" : "The EC2 Key Pair to allow Remote Desktop access or SSH to the instances.",
			"Type" : "String",
			"Default" : "Your_KeyPair_Name"
		},
		"MinSize" : {
			"Description" : "Minimum number of EC2 instances.",
			"Type" : "Number",
			"Default" : "2"
		},
		"MaxSize" : {
			"Description" : "Maximum number of EC2 instances.",
			"Type" : "Number",
			"Default" : "4"
		}
	},

	"Resources": {
		
		"LoadBalancerSecurityGroup": {
			"Type": "AWS::EC2::SecurityGroup",
			"Properties": {
				"GroupDescription": "Enable HTTP access on port 80 and 443.",
				"VpcId" : { "Ref" : "VpcId" },
				"SecurityGroupIngress": [{
				                        	 "IpProtocol": "tcp",
				                        	 "FromPort": "80" ,
				                        	 "ToPort": "80" ,
				                        	 "CidrIp" : "0.0.0.0/0"
											 },{
 				                        	 "IpProtocol": "tcp",
				                        	 "FromPort": "443" ,
				                        	 "ToPort": "443" ,
                                             "CidrIp" : "0.0.0.0/0"
				                         }],
		        "SecurityGroupEgress" : [{
											 "IpProtocol" : "tcp",
											 "FromPort" : "6080",
											 "ToPort" : "6080",
											 "CidrIp" : "0.0.0.0/0"
											 },{
				                        	 "IpProtocol": "tcp",
				                        	 "FromPort": "6443" ,
				                        	 "ToPort": "6443" ,
				                        	 "CidrIp" : "0.0.0.0/0"
				                         }]
						  }
			},
		"ELB" : {
			"Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
			"Properties" : {
				"Subnets" : { "Ref" : "Subnets" },
				"SecurityGroups" : [ { "Ref" : "LoadBalancerSecurityGroup" } ],				
				"Listeners" : [ {
					"LoadBalancerPort" : "80",
					"InstancePort" : "6080" ,
					"Protocol" : "HTTP"
				}],
				"HealthCheck" : {
					"Target" : "HTTP:6080/arcgis/rest/info/healthcheck",
					"HealthyThreshold" : "3",
					"UnhealthyThreshold" : "5",
					"Interval" : "30",
					"Timeout" : "5"
				}
			}
		},
		
		"InstanceSecurityGroup": {
			"Type": "AWS::EC2::SecurityGroup",
			"Properties": {
				"GroupDescription": "Enable HTTP access on 6080 and 6443 from ELB.",
				"VpcId" : { "Ref" : "VpcId" },
				"SecurityGroupIngress": [{
				                        	 "IpProtocol": "tcp",
				                        	 "FromPort": "6080" ,
				                        	 "ToPort": "6080" ,
											 "SourceSecurityGroupId": { "Ref" : "LoadBalancerSecurityGroup" }
				                         },{
				                        	 "IpProtocol": "tcp",
				                        	 "FromPort": "6443" ,
				                        	 "ToPort": "6443" ,
				                        	 "SourceSecurityGroupId": { "Ref" : "LoadBalancerSecurityGroup" }
				                         }]
			}
		},
		
		"LaunchConfig": {
			"Type": "AWS::AutoScaling::LaunchConfiguration",
			"Properties": {
				"ImageId": {"Ref" : "AMI"},
				"InstanceType": {"Ref": "InstanceType"},
				"KeyName": {"Ref": "KeyName"},
				"SecurityGroups": [{"Ref": "InstanceSecurityGroup"}],
				"InstanceMonitoring": true
			}
		},
		
		"AutoScalingGroup": {
			"UpdatePolicy" : {
				"AutoScalingRollingUpdate" : {
					"MinInstancesInService" : {"Ref" : "MinSize"},
					"MaxBatchSize" : "3",
					"PauseTime" : "PT15M"
				}
			},
			"Type": "AWS::AutoScaling::AutoScalingGroup",
			"Properties": {
				"AvailabilityZones" : { "Ref" : "AZs" },
				"VPCZoneIdentifier" : { "Ref" : "Subnets" },				
				"Cooldown": "300",
				"MaxSize": {"Ref" : "MaxSize"},
				"MinSize": {"Ref" : "MinSize"},
				"LaunchConfigurationName": {"Ref": "LaunchConfig"},
                "HealthCheckType" : "EC2",
                "HealthCheckGracePeriod" : "3600",
				"LoadBalancerNames": [{"Ref": "ELB"}],
				"Tags": [{"Key": "Name", "Value": {"Ref": "AWS::StackName"}, "PropagateAtLaunch" : true}]
			}
		},

		"ScaleUpPolicy" : {
			"Type" : "AWS::AutoScaling::ScalingPolicy",
			"Properties" : {
				"AdjustmentType" : "ChangeInCapacity",
				"AutoScalingGroupName" : { "Ref" : "AutoScalingGroup" },
				"Cooldown" : "60",
				"ScalingAdjustment" : "1"
			}
		},

		"ScaleDownPolicy" : {
			"Type" : "AWS::AutoScaling::ScalingPolicy",
			"Properties" : {
				"AdjustmentType" : "ChangeInCapacity",
				"AutoScalingGroupName" : { "Ref" : "AutoScalingGroup" },
				"Cooldown" : "60",
				"ScalingAdjustment" : "-1"
			}
		},

		"CPUAlarmHigh": {
			"Type": "AWS::CloudWatch::Alarm",
			"Properties": {
				"AlarmDescription": "Scale-up if CPU > 80% for 10 minutes",
				"MetricName": "CPUUtilization",
				"Namespace": "AWS/EC2",
				"Statistic": "Average",
				"Period": "300",
				"EvaluationPeriods": "2",
				"Threshold": "80",
				"AlarmActions": [ { "Ref": "ScaleUpPolicy" } ],
				"Dimensions": [
				               {
				            	   "Name": "AutoScalingGroupName",
				            	   "Value": { "Ref": "AutoScalingGroup" }
				               }
				               ],
				               "ComparisonOperator": "GreaterThanThreshold"
			}
		},

		"CPUAlarmLow": {
			"Type": "AWS::CloudWatch::Alarm",
			"Properties": {
				"AlarmDescription": "Scale-down if CPU < 20% for 10 minutes",
				"MetricName": "CPUUtilization",
				"Namespace": "AWS/EC2",
				"Statistic": "Average",
				"Period": "300",
				"EvaluationPeriods": "2",
				"Threshold": "20",
				"AlarmActions": [ { "Ref": "ScaleDownPolicy" } ],
				"Dimensions": [
				               {
				            	   "Name": "AutoScalingGroupName",
				            	   "Value": { "Ref": "AutoScalingGroup" }
				               }
				               ],
				               "ComparisonOperator": "LessThanThreshold"
			}
		}
	},

	"Outputs": {
		"RestURL": {
			"Value": {
				"Fn::Join": ["", ["http://", {"Fn::GetAtt": ["ELB", "DNSName" ]}, "/arcgis/rest"]]
			},
			"Description" : "ArcGIS Server REST Services Directory URL"
		}
	}   

}

此模板中的参数

AMI 参数用于设置在启动此堆栈中的实例时使用的 AMI ID。在运行 ArcGIS Server 的自定义 AMI 中进行此设置。

VPCId 参数是用于启动堆栈的虚拟私有云的物理 ID。

Subnets 参数指定要启动堆栈的 VPC 子网的列表(以逗号分隔)。为获得高可用性,可在多个区中指定子网。堆栈中的实例将分布到各个区。

AZ 参数是覆盖所列子网的可用区的名称列表(以逗号分隔)。

InstanceType 参数用于设置在启动堆栈中的实例时使用的 EC2 实例类型。设置该参数时要特别谨慎,因为它可以影响 AWS 成本和 Esri 许可成本。这些成本将乘以使用自动伸缩组启动的实例数。

KeyName 是可用于检索实例管理员密码的密钥对的名称。使用模板前,需要创建密钥对文件。如果要通过远程桌面或 SSH 连接到实例,则需要设置此选项。

MinSize 是任意时间参与堆栈的最小实例数。创建堆栈时将立即启动该数量的实例。如果将此值设置为 2 或更大值,则在实例不可用时,可避免 ArcGIS Server 不可用。如果仅找到一个实例,CloudFormation 将立即创建第二个实例。

MaxSize 是指在不考虑自动伸缩触发器或实例 CPU 使用率的情况下,任意时间允许参与堆栈的最大实例数。

此模板中的资源

LoadBalancerSecurityGroup 资源确定弹性负载均衡器的访问规则,其中包括接收和转发流量所经过的端口。

ELB 资源描述堆栈中的弹性负载均衡器 (ELB)。ELB 是向 ArcGIS Server 发出的所有 web 请求的入口点。它将请求分配至可用的 ArcGIS Server 实例。可以使用 ELB 的属性来调整负载均衡器端口、实例端口(对于受 SSL 保护的站点,可能不是默认的 6080,而变为 6443)以及健康检查设置。

InstanceSecurityGroup 资源确定将应用到此堆栈中启动的所有实例的访问规则。请注意,您可以设置入口规则,用于确定对实例开放的端口。在此模板中,允许弹性负载均衡器组访问端口 6080 上的实例。

LaunchConfig 资源引入模板用户设置的一些参数,用于确定要启动的实例类型以及要应用的 AMI。

AutoScalingGroup 资源用于设置为响应触发器(例如 CPU 使用率)而在堆栈中添加和移除实例的时间方面的规则。此资源还包含更新策略,此策略用于确定更新 AMI 时,立即更新的实例数。这些更新按滚动形式加以应用,这样,整个堆栈便不会因更新而离线。MaxBatchSize 表示立即更新的实例数,最好设置为小于堆栈的 MinSize 属性,这样可确保更新期间实例始终可用。

ScaleUpPolicy 资源定义在负荷较高的情况下如何向堆栈添加实例。稍后,CPUAlarmHigh 资源会在模板中引用此资源。

ScaleDownPolicy 资源定义在负荷较低的情况下如何从堆栈中移除实例。稍后,CPUAlarmLow 资源会在模板中引用此资源。

CPUAlarmHigh 资源用于为将导致实例添加到堆栈的警报设置特定参数。在此模板中,当 CPU 使用率连续 10 分钟超过 80% 时,将添加实例。

CPUAlarmLow 资源用于为将导致实例从堆栈中移除的警报设置特定参数。在此模板中,当 CPU 使用率连续 10 分钟低于 20% 时,将移除实例。

有关可在 CloudFormation 模板中加入的所有 JSON 属性的详细示例,请参阅 AWS 文档中的使用模板部分。

5/15/2014