我们提供了多种场景的模版供您选择,如下为当前支持的场景及模版。
序号 | 名称 | 描述(用途) | 链接 |
---|---|---|---|
1 | ACS-ECS-BulkyDeleteInstances | 批量删除ECS按量付费实例。 | YAML |
2 | ACS-ECS-BulkyDeleteInstancesWithApproval | 通过审批后删除ECS按量付费实例。 | YAML |
3 | ACS-ECS-BulkyDeletePrepaidInstances | 批量删除ECS预付费实例。指定的ECS实例必须处于已停止状态。 | YAML |
4 | ACS-ECS-BulkyInstallLogAgent | 批量在ECS实例上安装SLS代理。 | YAML |
5 | ACS-ECS-BulkyRebootInstances | 批量重启ECS实例。 | YAML |
6 | ACS-ECS-BulkyRunCommand | 批量在多台ECS实例上运行云助手命令。 | YAML |
7 | ACS-ECS-BulkyStartInstances | 批量启动ECS实例。 | YAML |
8 | ACS-ECS-BulkyStopInstances | 批量停止ECS实例。 | YAML |
9 | ACS-ECS-BulkyTagInstanceByLinuxKernelVersion | 批量通过指定实例IDs将Linux内核版本用作标记值标记ECS实例。 | YAML |
10 | ACS-ECS-BulkyTagInstanceByOSType | 批量通过指定实例IDs将操作系统类型用作标记值标记ECS实例。 | YAML |
11 | ACS-ECS-BulkyTagInstanceByRunCommandResult | 批量根据运行云助手命令的结果标记实例。 | YAML |
12 | ACS-ECS-BulkyUpgradeInternetBandwidth | 批量升级ECS实例公网带宽。 | YAML |
13 | ACS-ECS-CloneInstancesAcrossAZ | 跨可用区克隆ECS实例。 | YAML |
14 | ACS-ECS-CloneInstancesAcrossRegion | 跨地域克隆ECS实例。 | YAML |
15 | ACS-ECS-ConvertsPublicIPToNewEIPByInstanceId | 将一台网络类型为专有网络VPC的ECS实例的公网IP转化为其它弹性公网IP。 | YAML |
16 | ACS-ECS-RunInstancesWithApproval | 通过审批后创建ECS实例。 | YAML |
17 | ACS-ECS-RunRemoteShellScript | 运行远端shell脚本。 | YAML |
18 | ACS-ECS-RunShellScript | 运行shell脚本 | YAML |
19 | ACS-ECS-ScheduleToRebootInstances | 定时重启ECS实例。 | YAMLJSON |
20 | ACS-ECS-ScheduleToStartInstances | 定时启动ECS实例。 | YAML |
21 | ACS-ECS-ScheduleToStopInstances | 定时停止ECS实例。 | YAML |
22 | ACS-ECS-ScheduleToUpgradeInternetBandwidth | 定时升级ECS实例临时带宽。 | YAML |
23 | ACS-ECS-TagInstanceByLinuxKernelVersion | 通过Linux内核版本用作标记键标记一台ECS实例。 | YAML |
24 | ACS-ECS-TagInstanceByOSType | 将操作系统类型用作标记值标记一台ECS实例。 | YAML |
25 | ACS-ECS-TagInstanceByRunCommandResult | 根据运行云助手命令的结果标记实例。 | YAML |
26 | ACS-ECS-UpdateImage | 通过运行命令更新一个已存在的ECS镜像后创建一个新ECS镜像。 | YAML |
27 | ACS-ESS-LifeCycleModifyMongoDBIPWhitelist | 根据设置MongoDB实例白名单结果修改伸缩活动的等待状态。 | YAML |
28 | ACS-ESS-LifeCycleModifyRedisIPWhitelist | 根据设置Redis实例白名单结果修改伸缩活动的等待状态。 | YAML |
29 | ACS-InstallXDragonAndCloudMonitor | 批量安装神龙硬件检测插件、云监控、smartmontools,以及卸载与更新神龙硬件检测插件。 | YAML |
从实例中拷贝文件到OSS
我们经常遇到从某台线上的机器把日志文件拷贝出来或者是进程卡住了,jstack一下输出到某个文件再进行分析。我们使用osscmd把数据导到oss里,但是手动配置过程实在是过于繁琐。通过如下模版您可很容易地处理此需求。
模版内容(JSON格式):
{
"FormatVersion": "OOS-2019-06-01",
"Description": "Tag ECS Instance by the RunCommand invocation result.",
"Parameters": {
"InstanceId": {
"Type": "String",
"Description": "the Instance Id to operate in linux.",
"MinLength": 1,
"MaxLength": 30
},
"SrcUrl": {
"Type": "String",
"Description": "command content to run in linux ecs."
},
"DestUrl": {
"Type": "String",
"Description": "command content to run in linux ecs."
},
"InstanceAssumeRole": {
"Type": "String",
"Description": ""
},
"OOSAssumeRole": {
"Type": "String",
"Description": "oos assume this role to execution task.",
"Default": "OOSServiceRole"
}
},
"RamRole": "{{OOSAssumeRole}}",
"Tasks": [{
"Name": "checkInstanceReady",
"Action": "ACS::CheckFor",
"Description": "describe instances",
"Properties": {
"API": "DescribeInstances",
"Service": "ECS",
"PropertySelector": "Instances.Instance[].Status",
"DesiredValues": [
"Running"
],
"Parameters": {
"InstanceIds": ["{{ InstanceId }}"]
}
}
},
{
"Name": "runCommand",
"Action": "ACS::ECS::RunCommand",
"Description": "",
"Properties": {
"commandContent": {
"Fn::Join": [ "\n", [
"test -e oos || mkdir oos;",
"cd oos;",
"test -e ossutil64 || wget https://oos-public.oss-{{ACS::RegionId}}-internal.aliyuncs.com/x64/ossutil64 && chmod 755 ossutil64",
"test -e jq || wget https://oos-public.oss-{{ACS::RegionId}}-internal.aliyuncs.com/x64/jq && chmod 755 jq",
"stsToken=`curl http://100.100.100.200/latest/meta-data/Ram/security-credentials/{{InstanceAssumeRole}}`",
"accessKeyId=`echo $stsToken |./jq .AccessKeyId | awk -F'\"' '{print $2}'` ;",
"accessKeySecret=`echo $stsToken | ./jq .AccessKeySecret | awk -F'\"' '{print $2}'` ;",
"securityToken=`echo $stsToken | ./jq .SecurityToken | awk -F'\"' '{print $2}'` ;",
"endpoint=https://oss-{{ACS::RegionId}}-internal.aliyuncs.com;",
"./ossutil64 -i $accessKeyId -k $accessKeySecret -t $securityToken -e $endpoint cp {{SrcUrl}} {{DestUrl}}"
]
]
},
"commandType": "RunShellScript",
"instanceId": "{{InstanceId}}"
},
"Outputs": {
"CommandOutput":{
"Type": "String",
"ValueSelector": "InvocationResult[].Output"
}
}
}
],
"Outputs": {}
}
给ECS实例自动打TAG
对于一般的资源管理需求,都是资源数量较多的情况,如当实例的数量较多时,对实例进行运维管理等操作就会变得比较困难,有时候甚至需要采取拆分账号的方式管理不同部门或者不同用途的资源。如果采用Tag进行资源的分类管理,会提供极大便利。
我们可以针对实例的使用场景进行分类打Tag,在一般的开发场景中,机器一般有多个分类:开发测试环境、打包环境、生产环境等。这些机器的运维管理是绝对隔绝的,因此要在Tag上对其进行区分,在开发测试机器上,可以增加标签(增加方式详见下一节)key为env、value为test;在生产机器上,可以增加标签key为env、value为product。形成类似如下图的机器分类

我们也可按kernelVersion,osType等场景分类来打Tag,osType分为linux、window等。kernerlVersion为uname-r的返回结果。以下模版可助您快速地按osType进行打标签。
模版内容(JSON格式):
{
"FormatVersion": "OOS-2019-06-01",
"Description": "tag instance by os type",
"Parameters": {
"InstanceId": {
"Type": "String",
"Description": "the InstanceId to tag",
"MinLength": 1,
"MaxLength": 30
},
"TagKey": {
"Type": "String",
"Description": "the tag key you specified"
},
"OOSAssumeRole": {
"Type": "String",
"Description": "The RAM role to be assumed by OOS.",
"Default": "OOSServiceRole"
}
},
"RamRole": "{{OOSAssumeRole}}",
"Tasks": [
{
"Name": "queryInstanceOsType",
"Action": "ACS::ExecuteApi",
"Description": "",
"Properties": {
"API": "DescribeInstances",
"Service": "ECS",
"Parameters": {
"InstanceIds": [
"{{ InstanceId }}"
]
}
},
"Outputs": {
"OsType": {
"ValueSelector": "Instances.Instance[].OSType",
"Type": "String"
}
}
},
{
"Name": "tagResources",
"Action": "ACS::ExecuteApi",
"Description": "Tag Resources.",
"Properties": {
"API": "TagResources",
"Service": "ECS",
"Parameters": {
"ResourceType": "Instance",
"ResourceIds": [
"{{ InstanceId }}"
],
"Tags": [
{
"Key": "{{ TagKey }}",
"Value": "{{ queryInstanceOsType.OsType }}"
}
]
}
}
}
],
"Outputs": {
"OsType": {
"Type": "String",
"Value": "{{ queryInstanceOsType.OsType}}"
}
}
}
给实例加到SLS机器组
我们经常遇到以下场景,扩容一批机器需要配置SLS日志,对于已经配置好的SLS Logstore,我们只需要将机器加到机器组里。通过如下模版可助您轻松完成此操作。
模版内容(JSON格式):
{
"FormatVersion": "OOS-2019-06-01",
"Description": "Install Logtail agent on the ECS Instance.",
"Parameters": {
"InstanceId": {
"Type": "String",
"Description": "the Instance Id to install ilogtail",
"AllowedPattern": "i-[A-Za-z0-9]*",
"MinLength": 1,
"MaxLength": 30
},
"LogTailUserDefinedId": {
"Type": "String",
"Description": "the user defined Id write to /etc/ilogtail/user_defined_id",
"AllowedPattern": "[A-Za-z0-9\\-_]*",
"MinLength": 1,
"MaxLength": 30
},
"OOSAssumeRole": {
"Type": "String",
"Description": "The RAM role to be assumed by OOS.",
"Default": "OOSServiceRole"
}
},
"RamRole": "{{OOSAssumeRole}}",
"Tasks": [
{
"Name": "checkInstanceReady",
"Action": "ACS::CheckFor",
"Description": "describe instances.",
"Properties": {
"API": "DescribeInstances",
"Service": "ECS",
"PropertySelector": "Instances.Instance[].Status",
"DesiredValues": [
"Running"
],
"Parameters": {
"InstanceIds": [
"{{ InstanceId }}"
]
}
},
"Outputs": {
"InstanceIds": {
"ValueSelector": "InstanceIdSets.InstanceIdSet[]",
"Type": "List"
}
}
},
{
"Name": "createCommand",
"Action": "ACS::ExecuteApi",
"Description": "create the command to install logtail agent.",
"Properties": {
"API": "CreateCommand",
"Service": "ECS",
"Parameters": {
"CommandContent": {
"Fn::Base64Encode": "wget http://logtail-release-{{ACS::RegionId}}.oss-{{ACS::RegionId}}-internal.aliyuncs.com/linux64/logtail.sh -O logtail.sh; chmod 755 logtail.sh; ./logtail.sh install {{ACS::RegionId}}; echo {{ LogTailUserDefinedId }} > /etc/ilogtail/user_defined_id"
},
"Name": "oos-{{ACS::TemplateName}}",
"Type": "RunShellScript"
}
},
"Outputs": {
"CommandId": {
"Type": "String",
"ValueSelector": "CommandId"
}
}
},
{
"Name": "invokeCommand",
"Action": "ACS::ExecuteApi",
"Description": "invoke the command to install ilogtail",
"Properties": {
"Service": "ECS",
"API": "InvokeCommand",
"Parameters": {
"CommandId": "{{ createCommand.CommandId }}",
"InstanceIds": [
"{{ InstanceId }}"
]
}
},
"Outputs": {
"InvokeId": {
"Type": "String",
"ValueSelector": "InvokeId"
}
}
},
{
"Name": "untilInvocationDone",
"Action": "ACS::WaitFor",
"Description": "until invocation ready",
"MaxAttempts": 5,
"Properties": {
"Service": "ECS",
"API": "DescribeInvocations",
"Parameters": {
"InvokeId": "{{ invokeCommand.InvokeId }}"
},
"DesiredValues": [
"Finished"
],
"PropertySelector": "Invocations.Invocation[].InvokeStatus"
}
},
{
"Name": "describeInvocationResult",
"Action": "ACS::ExecuteApi",
"Description": "get the command invocation result",
"Properties": {
"Service": "Ecs",
"API": "DescribeInvocationResults",
"Parameters": {
"InvokeId": "{{ invokeCommand.InvokeId }}"
}
},
"Outputs": {
"InvocationResult": {
"Type": "String",
"ValueSelector": "Invocation.InvocationResults.InvocationResult[].Output"
},
"ExitCode": {
"Type": "Number",
"ValueSelector": "Invocation.InvocationResults.InvocationResult[].ExitCode"
}
}
},
{
"Name": "deleteCommand",
"Action": "ACS::ExecuteAPI",
"Description": "clean up the install ilogtail command",
"Properties": {
"Service": "ECS",
"Risk": "Normal",
"API": "DeleteCommand",
"Parameters": {
"CommandId": "{{ createCommand.CommandId }}"
}
}
}
],
"Outputs": {
"InvocationResult": {
"Type": "String",
"Value": {
"Fn::Base64Decode": "{{ describeInvocationResult.InvocationResult }}"
}
},
"ExitCode": {
"Type": "String",
"Value": "{{ describeInvocationResult.ExitCode }}"
}
}
}