The previous Douzi example demonstrates how to create a basic ELB to distribute data to different servers. Now let's go further. If the access data is too large, such as the Spring Festival Gala, such as the purchase of train tickets, how to automatically generate new servers according to the load for diversion, or automatically shut down unused servers when you are not busy. This function can be implemented by Auto Scaling.
Next, Douzi demonstrates how to create a Auto Scaling Group. It automatically adjusts the CPU Load under ELB, adds or removes Web Server, and automatically adds all automatically generated Web Server to my Elastic Load Balancer for diversion.
First, you need to create an AMI Image so that we can use this Image to automatically generate new identical Web Server.
Select Create Image on the created Lab Server
enter relevant information
next, we need to create Auto Scaling Configure files and Auto Scaling Group. This can be created through the management interface or through the command line. My following operations are mixed with two methods.
For more information, see my other blog.
after the configuration is completed, run and try it to view the Image of AMI.
This is the same as what I checked on the Management Interface
If you do not know the command line, you can also operate it directly through the graphical interface.
It looks good.
Next, we will create Auto Scaling Group. Here, I will create it through the management interface. After all, this is more intuitive.
Select a configuration file
the name is aws-as-group. Pay attention to Gou Xuan load balancing. By default, the generated VMS are all in the specified ELB, and all AZ can be put into the Subnet to achieve high availability.
create an Alarm and automatically send it to my SNS Topic
for example, if the average CPU utilization exceeds 50%, a server is automatically added.
If the average CPU utilization is lower than 30%, a server is automatically deleted.
Set it up
other warning notifications
set a Tag for Auto Scaling Group to distinguish
all configurations can be modified as needed.
Because the range I set is 1-3, there must be at least one EC2 instance in the Auto Scaling Group.
Automatically create a
enter the IP address of the new server and run it. The LAMP works properly.
Let's take a look at ELB. It has been automatically included.
If we stop or terminate an instance in an AS instance
it automatically creates a new
finally, let's do a load test.
Click ELB and click Generate load. The corresponding server automatically performs some empty operations to forcibly increase CPU usage.
The following illustration
you can see a sharp rise in cpu usage in cloudwatch.
A new instance is automatically created if the standard is exceeded.
However, the experiment above is not very accurate, because the CPU load is generated by one of the ELB servers. We can build a new server, independent of the ELB cluster, and then use genload. The php script sends a large number of requests to the specified ELB. In this way, a more real environment can be simulated and changes caused by changes in the CPU load of ELB can be observed.