Update images and run scripts

更新时间:
复制 MD 格式

You can use the rolling update feature of Auto Scaling to update images and run scripts for ECS instances in a scaling group. This makes managing these instances more efficient.

Background

Assume that a scaling group has the following properties:

  • The scaling group is in the China (Hangzhou) region.

  • The active scaling configuration uses the CentOS 6.4 64-bit public image.

  • The scaling group contains 100 ECS instances that are created based on the active scaling configuration. All ECS instances are in the In Service state.

  • The scaling group has no ongoing scaling activities.

Procedure

This tutorial describes how to update the images of ECS instances in a scaling group to Alibaba Cloud Linux 2 and then install Apache on the instances.

Step 1: Prepare custom images

  1. Log in to the ECS console.

  2. In the left-side navigation pane, choose Instances & Images > Instance.

  3. In the upper-left corner of the page, select a region and resource group.地域

  4. Create an ECS instance.

    1. In the upper-left corner of the Instances page, click Create Instance.

    2. On the Custom Launch tab, configure parameters such as the billing method, region, instance type, and image as needed.

      For more information about the parameters, see Parameter description.

      The following table describes the sample configurations used in this tutorial. Ensure that the other configurations match the active scaling configuration of the scaling group.

      Parameter

      Example

      Billing Method

      pay-as-you-go

      Region

      Region: China (Hangzhou)

      Network and Zone

      • Network: VPC

      • Zone: Random assignment

      Images

      • Type: Public image

      • Version: Alibaba Cloud Linux 2.1903 LTS 64-bit

    3. Before you create the instance, review the overall configuration on the right side of the page and set options such as the usage duration to ensure that the settings meet your requirements.

    4. Read and select ECS Terms of Service and other service agreements. Follow the on-screen instructions. Then, click Confirm Order.

    5. Confirm the fees for the ECS instance and complete the payment as prompted.

      After the instance is created, go to the instance list page to view the creation progress. When the instance enters the Running state, it has been successfully created. Then, rename the instance to Instance-ForCustomImage.

      Note

      Before you create a custom image, you can configure the created ECS instance Instance-ForCustomImage. For example, you can deploy applications or copy data to the instance. This reduces post-update maintenance.

  5. Prepare a custom image for the update.

    1. Find the ECS instance Instance-ForCustomImage, and in the Actions column, click image > Disks and Images > Create Custom Image.

    2. Configure the custom image.

      The following table describes the sample configurations used in this tutorial. Configure other parameters as needed.

      Parameter

      Example

      Custom Image Name

      Image-AliyunLinux

      Custom image description

      This image is used for the rolling update of ECS instances in the scaling group.

    3. Click Create.

  6. Prepare a custom image for rollback.

    1. Find an ECS instance that belongs to a scaling group, and in the Actions column, click image > Disks and Images > Create Custom Image.

    2. Configure the custom image.

      The following table describes the sample configurations used in this tutorial. Configure other parameters as needed.

      Parameter

      Example

      Custom Image Name

      Image-CentOSBck

      Custom image description

      This image is used to roll back the ECS instances in the scaling group if an issue occurs during the rolling update.

    3. Click Create.

  7. In the left-side navigation pane, choose Instances & Images > Images to view the creation progress of Image-AliyunLinux and Image-CentOSBck.

    The image is ready when its creation progress reaches 100%.

Step 2: Update image and run script

  1. Sign in to the Auto Scaling console.

  2. In the left-side navigation pane, click Scaling Groups.

  3. In the top navigation bar, select a region.

  4. Find the scaling group that you want to manage and open its details page in either of the following ways:

    • In the Scaling Group Name/ID column, click the ID of the scaling group.

    • In the Actions column, click Details.

  5. At the top of the page, click the Instance Refresh tab, and then find the rolling update list.

  6. Create and run an image update task.

    1. Click Create Execution Task.

    2. Configure the image update task.

      The following table describes the sample configurations used in this tutorial. Configure other parameters as needed.

      Parameter

      Example

      Task Description

      Update images from CentOS 6.4 64-bit to Alibaba Cloud Linux 2.1903 LTS 64-bit in batches.

      Task Type

      Update Image

      Image for Update

      Image-AliyunLinux

      Image for Rollback

      Image-CentOSBck

      Execution Batch

      10

      Suspension Policy

      Do Not Suspend

    3. Click Create Task.

    4. Review the impacts of the rolling update task. Click OK.

      The rolling update task starts automatically.

    After the task is complete, the images of the 100 ECS instances in the scaling group are updated to Alibaba Cloud Linux 2.1903 LTS 64-bit.

  7. Create and run a script execution task.

    1. Click Create Execution Task.

    2. Configure the script execution task.

      The following table describes the sample configurations used in this tutorial. Configure other parameters as needed.

      Parameter

      Example

      Task Description

      Install Apache and view the Apache service status.

      Task Type

      Script Execution

      Script for Execution

      # Install the Apache service.
      yum install -y httpd
      # Start the Apache service.
      systemctl start httpd
      # Enable the Apache service to start on boot.
      systemctl enable httpd
      # Check the status of the Apache service.
      systemctl status httpd

      Script for Rollback

      # Check the status of the Apache service.
      systemctl status httpd

      Execution Batch

      10

      Suspension Policy

      Do Not Suspend

    3. Click Create Task.

    4. Review the impacts of the rolling update task. Click OK.

      The rolling update task starts automatically.

    After the task is complete, Apache is installed on the 100 ECS instances in the scaling group, and the Apache service is active.查看Apache服务状态