Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use AWS Auto Scaling to dynamically add and decrease instances on demand

Shulou Source: shulou.com Published: 2022-06-03 01:02:33 09月25日 Update

First, background needs

When you don't know which type of EC2 instance you should choose, and when the business will peak, we can easily solve our problem by using Auto Scaling, which automatically expands and downsizes according to the load pressure we set to ensure the normal operation of the business with minimum cost.

Second, configure step 2.1.Create AMI

First, make an image of the host of the EC2 we are running, and set the internal service to self-startup to ensure that all services are available when the capacity is expanded.

2.2. Create a load balancer target group

Auto Scaling is used with ELB to dynamically distribute the load to the back-end machines, and we need a target group to store our Auto Scaling cluster machines.

2.3.Create Classic Load Balancer

2.4. Create a startup configuration

In order for instances to start stably, you can choose on-demand instances or Spot instances that are higher than the market price, and try to have as many as possible to ensure the success rate.

2.5.Create Auto Scaling group

I chose a bidding instance here and failed to start it several times, so I changed the startup configuration of an on-demand instance.

2.6. Testing

We log in to the first machine in the group and use the following command to pressurize CPU to see if a new instance is automatically started when the threshold is exceeded.

For i in `seq 1 $(cat / proc/cpuinfo | grep "processor" | wc-l) `; do dd if=/dev/zero of=/dev/null; done &

As you can see, the load of CPU has gone up:

Let's take a look at the event and find that a new instance has been launched:

Then we stop the stress test and wait for a while to check:

So far we have finished this test.

Fun play

We can install the web service, load the ELB to the new instance, and configure the specific content for each instance. We select the metadata of the instance. During startup, we can enter the following startup parameters:

#! / bin/bashyum install nginx-ysystemctl start nginxcurl http://169.254.169.254/latest/meta-data/public-ipv4 > / var/www/html/index.html

Http://169.254.169.254/latest/meta-data/ is the metadata information interface of the instance.

Http://docs.amazonaws.cn/AWSEC2/latest/UserGuide/ec2-instance-metadata.html

Welcome to scan the code and follow us for more information.

Tags: Instance time configuration machine guarantee service test selection business information pressure data goal face-to-face running dynamic convenient minimum clear balanced Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux NVidia OPPO Reno vpn Shulou Tech Info