You can use the Rolling Update feature to update images of and execute scripts on ECS instances with ease. This enhances the efficiency of managing ECS instances in a scaling group.

Prerequisites

Before you perform the operations provided in the tutorial, you must have registered an Alibaba Cloud account. To create an Alibaba Cloud account, click Create a new Alibaba Cloud account.

Procedure

The following section describes the status of a scaling group:
  • The scaling group is in China (Hangzhou).
  • The CentOS 6.4 64-bit public image is used in the active scaling configuration of the scaling group.
  • 100 ECS instances are created based on the active scaling configuration of the scaling group. All the instances are in the In Service state.
  • No scaling activities are in progress in the scaling group.
This topic describes how to update the images of ECS instances in a scaling group to the Alibaba Cloud Linux 2 image, and how to install Apache on the ECS instances after the images are updated. Perform the following operations:

Step 1: Create a custom image

  1. Log on to the ECS console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, choose Instances & Images > Instances.
  4. Creates an ECS instance.
    1. In the upper-right corner of the Instances page, click Create Instance.
    2. Configure parameters to create an instance.
      The following table describes the sample configurations of the instance. Configure other parameters and make sure that the configurations are the same as those of the active scaling configuration in the scaling group.
      Step Parameter Example
      Basic Configurations Billing Method Pay-As-You-Go
      Region
      • Region: China (Hangzhou)
      • Zone: Random
      Image
      • Type: Public Image
      • Version: Aliyun Linux 2.1903 LTS 64-bit
      System Configurations (Optional) Instance Name Instance-ForCustomImage
    3. Click Next: Preview.
    4. Read and select ECS Terms of Service, and then click Create Order.
    5. In the Created message, click Console to view the creation progress on the Instances page.
      If the instance is in the Running state, it is created.
      Note Before you create a custom image, you can configure the Instance-ForCustomImage instance, such as deploying applications and copying data. This helps reduce maintenance operations after the image is updated.
  5. Create a custom image to be used to update images of ECS instances in the scaling group.
    1. Find the Instance-ForCustomImage instance and choose More > Disk and Image > Create Custom Image in the Actions column.
    2. Configure parameters for the custom image.
      The following table describes the sample configurations of the image. Configure other parameters.
      Parameter Example
      Custom Image Name Image-AliyunLinux
      Custom Image Description The image used to update images of ECS instances in the scaling group
    3. Click Create.
  6. Create a custom image to be used to roll back images of ECS instances in the scaling group.
    1. Find an ECS instance that belongs to the scaling group and choose More > Disk and Image > Create Custom Image in the Actions column.
    2. Configure parameters for the custom image.
      The following table describes the sample configurations of the image. Configure other parameters.
      Parameter Example
      Custom Image Name Image-CentOSBck
      Custom Image Description The image used to roll back images of ECS instances in the scaling group when errors occur to the rolling update task
    3. Click Create.
  7. In the left-side navigation pane, choose Instances & Images > Images to view the creation progress of the Image-AliyunLinux and Image-CentOSBck images on the Images page.
    If the progress is 100%, the image is created.

Step 2: Update images and execute scripts

  1. Log on to the Auto Scaling console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, click Scaling Groups.
  4. Find the scaling group and use one of the following methods to open the details page of the scaling group:
    • Click the ID of the scaling group in the Scaling Group Name/ID column.
    • Click Details in the Actions column.
  5. In the left-side navigation pane, click Rolling Update.
  6. Create and execute an image update task.
    1. In the upper-left corner of the page, click Create Execution Task.
    2. Configure parameters for the rolling update task.
      The following table describes the sample configurations of the task. Configure other parameters.
      Parameter Example
      Task Description Update the image from CentOS 6.4 64-bit to Aliyun Linux 2.1903 LTS 64-bit in batches
      Task Type Image Update
      Image for Update Image-AliyunLinux
      Image for Rollback Image-CentOSBck
      Execution Batch 10
      Suspension Policy Automatic
    3. Click Create Task.
    4. Read the execution impact and click OK if you confirm the information.
      After you confirm the information, the rolling update task is automatically executed.
    After the task is complete, images of the 100 ECS instances in the scaling group are updated to Aliyun Linux 2.1903 LTS 64-bit.
  7. Create and execute a script execution task.
    1. In the upper-left corner of the page, click Create Execution Task.
    2. Configure parameters for the script execution task.
      The following table describes the sample configurations of the task. Configure other configurations.
      Parameter Example
      Task Description Install Apache and view the status of Apache
      Task Type Script Execution
      Script for Execution
      # Install Apache.
      yum install -y httpd
      # Start Apache.
      systemctl start httpd
      # Enable Apache to run at startup.
      systemctl enable httpd
      # View the status of Apache.
      systemctl status httpd
      Script for Rollback
      # View the status of Apache.
      systemctl status httpd
      Execution Batch 10
      Suspension Policy Automatic
    3. Click Create Task.
    4. Read the execution impact and click OK if you confirm the information.
      Then, the rolling update task is automatically executed.
    After the task is complete, Apache is installed on the 100 ECS instances in the scaling group. The status of Apache is active.View the status of Apache