All Products
Search
Document Center

Auto Scaling:Update images and execute scripts

Last Updated:Jun 19, 2024

The Rolling Update feature of Auto Scaling simplifies the process of updating images and running scripts on Elastic Compute Service (ECS) instances, providing a more efficient approach to managing instances within a scaling group.

Background information

For example, you have a scaling group with the following attributes:

  • 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.

Procedure

This topic describes how to update the images of ECS instances in a scaling group to Alibaba Cloud Linux 2 images and how to install Apache on the ECS instances after the images are updated.

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 the region and resource group to which the resource belongs. 地域

  4. Create an ECS instance.

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

    2. On the Custom Launch tab, select a billing method, region, instance type, and image.

      For information about each parameter on the Custom Launch tab, see the Parameters section in this topic.

      The following table shows the sample configurations of the instance. Configure other parameters based on your business requirements, and make sure that the configurations are the same as the active scaling configurations in the scaling group.

      Parameter

      Example

      Billing Method

      Pay-as-you-go

      Region

      China (Hangzhou)

      Network and Zone

      • Network: VPC

      • Zone: Random

      Image

      • Type: Public Image

      • Version: Alibaba Cloud Linux 2.1903 LTS 64-bit

    3. Before you click Create Order, check the instance configurations in the Configuration Summary section and configure parameters such as Duration on the right side of the page. Make sure that all configurations meet your business requirements.

    4. Read and select service agreements such as the ECS Terms of Service. If you already signed a service agreement, you do not need to re-sign the agreement. Follow the on-screen instructions. Then, click Create Order.

    5. Check the fees of the ECS instance and follow the on-screen instructions to complete the payment.

      After the ECS instance is created, go to the Instances page to check the state of the instance. When the ECS instance is in the Running state, the ECS instance is created. Remember to change the name of the ECS instance to Instance-ForCustomImage.

      Note

      Before you create a custom image, you can configure the Instance-ForCustomImage instance. For example, you can deploy applications and copy data. This helps reduce maintenance operations after the image is updated.

  5. Create a custom image from the ECS instance.

    1. Find the Instance-ForCustomImage ECS instance and choose image > Disk and Image > Create Custom Image in the Actions column.

    2. Configure parameters to complete image creation.

      The following table shows the sample configurations of the image. Configure other parameters based on your business requirements.

      Parameter

      Example

      Name

      Image-AliyunLinux

      Description

      The image that is used to update the images of ECS instances in the scaling group.

    3. Click OK.

  6. Prepare a custom image for rolling purposes.

    1. Find an ECS instance that belongs to the specified scaling group and choose image > Disk and Image > Create Custom Image in the Actions column.

    2. Configure parameters to complete image creation.

      The following table shows the sample configurations of the image. Configure other parameters based on your business requirements.

      Parameter

      Example

      Name

      Image-CentOSBck

      Description

      The image that is used to roll back the image of the ECS instance when an error occurs in the rolling update task.

    3. Click OK.

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

    An image is created when its creation progress reaches 100%.

Step 2: Update an image and execute a script

  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 the region where Auto Scaling is activated.

  4. Find a scaling group and use one of the following methods to go to the scaling group details page:

    • Click the ID of the scaling group in the Scaling Group Name/ID column.

    • Click Details in the Actions column.

  5. In the upper part of the scaling group details page, click the Rolling Update tab.

  6. Create and execute an image update task.

    1. Click Create Execution Task.

    2. Configure parameters to complete image update.

      The following table shows the sample configurations of the task. Configure other parameters based on your business requirements.

      Parameter

      Example

      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

      Update Image

      Image for Update

      Image-AliyunLinux

      Image for Rollback

      Image-CentOSBck

      Execution Batch

      10

      Suspension Policy

      Without Suspension

    3. Click Create Task.

    4. Read and understand the impacts of the rolling update task and click OK.

      Then, the rolling update task is automatically run.

    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 parameters to complete task creation.

      The following table shows the sample configurations of the task. Configure other parameters based on your business requirements.

      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 instance 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

      Without Suspension

    3. Click Create Task.

    4. Read and understand the impacts of the rolling update task and click OK.

      Then, the script execution task is automatically run.

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