本文介绍如何通过控制台及火山引擎提供的OpenAPI,查询与响应SystemMaintenance.Redeploy(系统维护,实例重新部署)事件,快速排除故障、确保云产品稳定运行。
当您购买的云服务器实例所在的宿主机(物理机)处于CPU过热、电源故障、风扇故障等亚健康状态,且该宿主机尚未宕机时,火山引擎将生成SystemMaintenance.Redeploy(系统维护,实例重新部署)事件并通知您。
收到通知后,您可以进行如下操作:
说明
若您还未授权,或已授权并已预约执行时间,但未到执行时间,此时,实例被开机或重启将会触发自动运维操作。
本文以授权运维操作为例说明。
重新部署实例将影响存储在本地盘的数据,请提前备份数据,以防数据丢失,例如通过硬盘、U盘等将重要数据拷贝到外部存储设备。
本实践以“事件监控”页面响应事件为例,您还可以前往实例详情页响应事件,操作详情可查看查询并处理事件中的实例详情页。
以实例触发SystemMaintenance.Redeploy(系统维护,实例重新部署)事件为例,更多事件类型可查看ECS事件类型汇总。
单击事件“操作”列的“授权重新部署”按钮,进行授权响应。
选择重新部署实例的执行维护时间并同意维护授权,包括立即执行和预约执行。
单击“确定”按钮,完成授权响应。
以JAVA语言接口为例,您可以参考如下顺序调用OpenAPI接口,查询、响应云服务器事件。
说明
调用DescribeSystemEvents接口,查询云服务器实例触发的事件信息。
请求示例:
public void queryInstanceEvents(){ //设置您的ak String ak = "Your AK"; //设置您的sk String sk = "Your SK"; //设置您要访问的地域,本示例为北京地域 String region = "cn-beijing"; //初始化apiclient ApiClient apiClient = new ApiClient() .setCredentials(Credentials.getCredentials(ak, sk)) .setRegion(region); EcsApi ecsApi = new EcsApi(apiClient); DescribeSystemEventsRequest describeSystemEventsRequest = new DescribeSystemEventsRequest(); // 指定待查询的实例ID describeSystemEventsRequest.setResourceIds(Arrays.asList("<A实例ID>","<B实例ID>","<C实例ID>")); // 筛选生成事件的起始时间 describeSystemEventsRequest.setCreatedAtStart("2023-05-20T01:29:38+08:00"); // 筛选生成事件的结束时间 describeSystemEventsRequest.setCreatedAtEnd("2023-05-25T18:29:38+08:00"); try { DescribeSystemEventsResponse describeSystemEventsResponse = ecsApi.describeSystemEvents(describeSystemEventsRequest); System.out.println(describeSystemEventsResponse); } catch (ApiException e) { System.out.println(e.getResponseBody()); } }
返回示例:
class DescribeSystemEventsResponse { nextToken: systemEvents: [class SystemEventForDescribeSystemEventsOutput { createdAt: 2023-05-25T14:15:21+08:00 id: e-ycfroor651gh9zxxx operatedEndAt: 2023-05-29T11:58:30+08:00 operatedStartAt: 2023-05-28T23:58:30+08:00 resourceId: <A实例ID> status: Inquiring type: SystemFailure_Redeploy updatedAt: 2023-05-26T11:58:30+08:00 }, class SystemEventForDescribeSystemEventsOutput { createdAt: 2023-05-24T10:27:02+08:00 id: e-ycfoo7134kgsnzdvxxx operatedEndAt: operatedStartAt: resourceId: <B实例ID> status: Succeeded type: CreateInstance updatedAt: 2023-05-24T10:27:12+08:00 }, class SystemEventForDescribeSystemEventsOutput { createdAt: 2023-05-23T17:44:17+08:00 id: e-ycfmuzgy5im0xxxx operatedEndAt: operatedStartAt: resourceId: <C实例ID> status: Succeeded type: RunInstance updatedAt: 2023-05-23T17:44:20+08:00 }] }
调用UpdateSystemEvents接口,响应SystemMaintenance_Redeploy(系统维护,实例重新部署)事件,授权火山引擎运维人员进行重新部署实例,排除故障。
说明
请求示例:
public void updateEvents(){ //设置您的ak String ak = "Your AK"; //设置您的sk String sk = "Your SK"; //设置您要访问的地域,本示例为北京地域 String region = "cn-beijing"; //初始化apiclient ApiClient apiClient = new ApiClient() .setCredentials(Credentials.getCredentials(ak, sk)) .setRegion(region); EcsApi ecsApi = new EcsApi(apiClient); UpdateSystemEventsRequest updateSystemEventsRequest = new UpdateSystemEventsRequest(); // 传入需要响应的事件ID updateSystemEventsRequest.setEventIds(Arrays.asList("e-ycfu1fit1f8hcczyxxx")); // 响应事件 updateSystemEventsRequest.setStatus("Executing"); // 指定重新部署实例时间窗 updateSystemEventsRequest.setOperatedStartAt("2023-05-28T23:58:30+08:00"); updateSystemEventsRequest.setOperatedEndAt("2023-05-29T11:58:30+08:00"); try { UpdateSystemEventsResponse updateSystemEventsResponse = ecsApi.updateSystemEvents(updateSystemEventsRequest); System.out.println(updateSystemEventsResponse); } catch (ApiException e) { System.out.println(e.getResponseBody()); } }
返回示例:
class UpdateSystemEventsResponse { operationDetails: [class OperationDetailForUpdateSystemEventsOutput { error: null eventId: e-ycfu1fit1f8hcczxxx }] }
调用DescribeSystemEvents接口,传入已响应的事件ID,查询事件当前状态等信息。
请求示例:
public void queryInstanceEvents(){ //设置您的ak String ak = "Your AK"; //设置您的sk String sk = "Your SK"; //设置您要访问的地域,本示例为北京地域 String region = "cn-beijing"; //初始化apiclient ApiClient apiClient = new ApiClient() .setCredentials(Credentials.getCredentials(ak, sk)) .setRegion(region); EcsApi ecsApi = new EcsApi(apiClient); DescribeSystemEventsRequest describeSystemEventsRequest = new DescribeSystemEventsRequest(); // 指定待查询事件ID describeSystemEventsRequest.setEventIds(Arrays.asList("e-ycfu1fit1f8hcczyxxx")); try { DescribeSystemEventsResponse describeSystemEventsResponse = ecsApi.describeSystemEvents(describeSystemEventsRequest); System.out.println(describeSystemEventsResponse); } catch (ApiException e) { System.out.println(e.getResponseBody()); } }
返回示例:
事件处于执行中状态示例如下:
class DescribeSystemEventsResponse { nextToken: systemEvents: [class SystemEventForDescribeSystemEventsOutput { createdAt: 2023-05-26T11:58:30+08:00 id: e-ycfu1fit1f8hcczyxxx operatedEndAt: 2023-05-29T11:58:30+08:00 operatedStartAt: 2023-05-28T23:58:30+08:00 resourceId: <A实例ID> status: Executing type: SystemMaintenance_Redeploy updatedAt: 2023-05-26T14:19:19+08:00 }] }
事件执行成功示例如下:
class DescribeSystemEventsResponse { nextToken: systemEvents: [class SystemEventForDescribeSystemEventsOutput { createdAt: 2023-05-26T11:58:30+08:00 id: e-ycfu1fit1f8hcczyxxx operatedEndAt: 2023-05-29T11:58:30+08:00 operatedStartAt: 2023-05-28T23:58:30+08:00 resourceId: <A实例ID> status: Succeeded type: SystemMaintenance_Redeploy updatedAt: 2023-05-28T23:58:30+08:00 }] }