安装并配置阿里云CLI
本文以Mac-os为例,其他系统安装可参考阿里云CLI。
1.首先为阿里云CLI创建一个RAM用户来获取AK,详细操作请参考创建RAM用户。
2.为创建的RAM用户授权:
a. 云账号登录RAM控制台。
b. 在左侧导航栏的人员管理菜单下,单击用户。
c. 在用户登录名称/显示名称列表下,找到目标RAM用户。
d. 单击添加权限,被授权主体会自动填入。
e. 在左侧权限策略名称列表下,单击AliyunECSFullAccess, AliyunESSFullAccess, AliyunOOSFullAccess, AliyunOSSFullAccess。
f. 单击确定。
g. 单击完成。
3.安装阿里云CLI。
brew install aliyun-cli
4.配置CLI。
aliyun configure
5.验证CLI可用,若可用,可在终端看到输出当前支持的多个地域。
aliyun ecs DescribeRegions
通过CLI执行滚动升级
1.通过更新镜像滚动升级。
模板参数说明请查看ACS-ESS-RollingUpdateByReplaceSystemDiskInScalingGroup模板详情。
执行命令如下:
aliyun oos StartExecution --TemplateName ACS-ESS-RollingUpdateByReplaceSystemDiskInScalingGroup --Parameters '{
"invokeType": "invoke",
"imageId": "centos_7_8_amd_x64_20G_alibase_20200806.vhd",
"sourceImageId": "centos_8_2_x64_20G_alibase_20200717.vhd",
"OOSAssumeRole": "",
"exitProcess": [],
"scalingConfigurationId": "asc-bp14e7lqyl66ca4rp4rb",
"enterProcess": [
"ScaleIn",
"ScaleOut",
"HealthCheck",
"AlarmNotification",
"ScheduledAction"
],
"scalingGroupId": "asg-bp1cjeuvlt1e1i1t",
"batchNumber": 2,
"batchPauseOption": "Automatic"
}'
回滚命令如下:
aliyun oos StartExecution --TemplateName ACS-ESS-RollingUpdateByReplaceSystemDiskInScalingGroup --Parameters '{
"invokeType": "rollback",
"sourceImageId": "centos_8_2_x64_20G_alibase_20200717.vhd",
"OOSAssumeRole": "",
"scalingConfigurationId": "asc-bp14e7lqyl66ca4rp4rb",
"scalingGroupId": "asg-bp1cjeuvlt1e1i1t",
"sourceExecutionId": "exec-6801252e615c4067a2ef",
"batchNumber": 2,
"batchPauseOption": "Automatic"
}'
2.通过脚本执行滚动升级。
模板参数说明请查看ACS-ESS-RollingUpdateByRunCommandInScalingGroup模板详情。
执行命令如下:
aliyun oos StartExecution --TemplateName ACS-ESS-RollingUpdateByRunCommandInScalingGroup --Parameters '{
"invokeType": "invoke",
"commandType": "RunShellScript",
"OOSAssumeRole": "",
"exitProcess": [],
"invokeScript": "df -h\nifconfig",
"rollbackScript": "df -h\nifconfig",
"enterProcess": [
"ScaleIn",
"ScaleOut",
"HealthCheck",
"AlarmNotification",
"ScheduledAction"
],
"scalingGroupId": "asg-bp1cjeuvlt1e1i1t",
"batchNumber": 2,
"batchPauseOption": "Automatic"
}'
回滚命令如下:
aliyun oos StartExecution --TemplateName ACS-ESS-RollingUpdateByRunCommandInScalingGroup --Parameters '{
"invokeType": "rollback",
"commandType": "RunShellScript",
"OOSAssumeRole": "",
"rollbackScript": "df -h\nifconfig",
"scalingGroupId": "asg-bp1cjeuvlt1e1i1t",
"sourceExecutionId": "exec-f577d2a639f24f4e9c0a",
"batchNumber": 2,
"batchPauseOption": "Automatic"
}'
3.通过安装OOS软件包滚动升级。
模板参数说明请查看ACS-ESS-RollingUpdateByConfigureOOSPackage模板详情。
执行命令如下:
aliyun oos StartExecution --TemplateName ACS-ESS-RollingUpdateByConfigureOOSPackage --Parameters '{
"invokeType": "invoke",
"OOSAssumeRole": "",
"exitProcess": [],
"action": "install",
"enterProcess": [
"ScaleIn",
"ScaleOut",
"HealthCheck",
"AlarmNotification",
"ScheduledAction"
],
"packageVersion": "v4",
"packageName": "wordpress",
"scalingGroupId": "asg-bp1cjeuvlt1e1i1t",
"batchNumber": 2,
"batchPauseOption": "Automatic"
}'
回滚命令如下:
aliyun oos StartExecution --TemplateName ACS-ESS-RollingUpdateByConfigureOOSPackage --Parameters '{
"invokeType": "rollback",
"OOSAssumeRole": "",
"packageVersion": "v3",
"packageName": "wordpress",
"scalingGroupId": "asg-bp1cjeuvlt1e1i1t",
"sourceExecutionId": "exec-b1a293da254042f492f6",
"batchNumber": 2,
"batchPauseOption": "Automatic"
}'