The Rolling Update feature allows you to update images and execute scripts on ECS instances with just a few clicks. This way, you can manage ECS instances in a scaling group in a more efficient manner.

Prerequisites

An Alibaba Cloud account is created. To create an Alibaba Cloud account, go to the account registration page.

Procedure

This topic uses a scaling group that meets the following requirements:
  • 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.
  • One hundred ECS instances are created based on the active scaling configuration of the scaling group. All 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 the preceding scaling group to Alibaba Cloud Linux 2 images. This topic also describes how to install Apache on the ECS instances after the images are updated. To update images and execute scripts, perform the following steps:

Step 1: Create a custom image

  1. Log on to the ECS console.
  2. In the left-side navigation pane, choose Instances & Images > Instances.
  3. In the top navigation bar, select a region.
  4. Create an ECS instance.
    1. In the upper-left corner of the Instances page, click Create Instance.
    2. Configure the parameters that are required to create an instance.
      The following table shows the sample configurations of the instance. Configure other parameters based on your business requirements. Make sure that the configurations are the same as the active scaling configurations in the scaling group.
      Step Parameter Example value
      Basic Configurations Billing Method Pay-As-You-Go
      Region
      • Region: China (Hangzhou)
      • Zone: Random
      Image
      • Type: Public Image
      • Version: Alibaba Cloud Linux 2.1903 LTS 64-bit
      System Configurations (Optional) Instance Name Instance-ForCustomImage
    3. Click Next: Preview.
    4. Read and select ECS Service Terms, and then click Create Order.
    5. Check the fees of the ECS instance and follow the on-screen instructions to complete the payment.
      After the instance is created, go to the Instances page to check the status of the instance. When the instance is in the Running state, the instance is created.
      Note Before you create a custom image, you can configure the ECS instance Instance-ForCustomImage. For example, you can deploy applications and copy data. This helps reduce maintenance operations after the image is updated.
  5. Create a custom image that you want to use to update the 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 the parameters of the custom image.
      The following table shows the sample configurations of the image. Configure other parameters based on your business requirements.
      Parameter Example value
      Custom Image Name Image-AliyunLinux
      Custom Image Description The image that is used to update the images of ECS instances in the scaling group.
    3. Click Create.
  6. Create a custom image that you want to use to roll back the 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 the parameters of the custom image.
      The following table shows the sample configurations of the image. Configure other parameters based on your business requirements.
      Parameter Example value
      Custom Image Name Image-CentOSBck
      Custom Image Description The image that is used to roll back the images of ECS instances in the scaling group when errors occur in 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 left-side navigation pane, click Scaling Groups.
  3. In the top navigation bar, select a region.
  4. Find a scaling group and go to the details page of the scaling group. You can use one of the following methods to go to the details page:
    • Click the ID of the scaling group in the Scaling Group Name/ID column.
    • Click Details in the Actions column of the scaling group.
  5. In the upper part of the page, click the Rolling Update tab.
  6. Create and execute an image update task.
    1. Click Create Execution Task.
    2. Configure the parameters of the image update task.
      The following table shows the sample configurations of the task. Configure other parameters based on your business requirements.
      Parameter Example value
      Task Description Update multiple images from CentOS 6.4 64-bit to Alibaba Cloud Linux 2.1903 LTS 64-bit at the same time.
      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. Learn about the risks that are associated with the execution of the update task and click OK if you agree.
      The update task is automatically executed.
    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 execute a script execution task.
    1. Click Create Execution Task.
    2. Configure the parameters of the script execution task.
      The following table shows the sample configurations of the task. Configure other parameters based on your business requirements.
      Parameter Example value
      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. Learn about the risks that are associated with the execution of the task and click OK if you agree.
      The script execution task is automatically executed.
    After the task is complete, Apache is installed on the 100 ECS instances in the scaling group. Apache is in the active state. View the status of Apache