Admin-Ahead Community

Linux => Virtualization => Topic started by: aravindm on June 10, 2018, 02:52:58 pm

Title: Configuring and setting up auto scaling in AWS
Post by: aravindm on June 10, 2018, 02:52:58 pm
What is Auto scaling?

In basic term auto scaling means that, adding compute instances EC2 when the load on the server reaches particular threshold on the higher side. Also removing the compute instance EC2 when the load on the server comes back to normal. This particularly helps to making sure that required amount of compute power is available whenever required.

This also helps to avoid over usage and under usage of resources.

What things required to configure-setup auto scaling in AWS

1. Launch Configuration (Template)

2. Auto scaling Group

Steps to configure-setup auto scaling in AWS for web server

As a demo we will be using auto scaling for our web server. However you need to use auto scaling as per your need.

Step 1: Building web server.

Firstly we need to configure web server

Step 2: Create AMI image.

In the next step we need to create AMI image of the web server created so that additional servers can be added when required.

Step 3: Create launch configuration using the web server AMI .

Now to create launch configuration go to Auto scaling –> Launch configurations option as below in the left pane of AWS console window.

(https://snag.gy/wNxOsA.jpg)

   
(https://snag.gy/5EnhQ3.jpg)

   
(https://snag.gy/rWTJOl.jpg)

   
For this select My AMIs and click on select button.

(https://snag.gy/uO02hV.jpg)


(https://snag.gy/tmMTBA.jpg)

   
(https://snag.gy/RxpLHC.jpg)

   
(https://snag.gy/by3Jp2.jpg)

Step 4: Create Auto Scaling Group:

In the next step you need to create Auto Scaling Group.  In the first step use below options.

Click on “Next: Configure scaling Policies” button.

(https://snag.gy/LM6YRZ.jpg)

   
(https://snag.gy/7sqLj6.jpg)

      3. Now for “Take the action:” option under “Increase Group Size” select Add 1 instance. In case you wanted to have more you  can use accordingly.
      4. Click on “Add new alarm”  under “Increase Group Size” and select following options in next popup. This configuration we will add new EC2 instance once CPU utilization increased above 30% and wait time is 5 minutes.

(https://snag.gy/1PWRrC.jpg)

      5. Now for Scaling down, for “Take the action:” option under “Decrease Group Size” select Remove 1 instance.
      6. Click on “Add new alarm”  under “Decrease Group Size” and select following options in next popup. This configuration we will remove EC2 instance once CPU utilization decreased below 20% and wait time is 5 minutes.

(https://snag.gy/DyMdKx.jpg)

       7.Click on “Next:Configure Notifications” and select below options. You can also create new topics if you want. Next click on Next configure Tags button. This configuration item will send notification for triggered events.

(https://snag.gy/HBVM8e.jpg)

       8. Select following options in the Tag options and click review button.
       9. If everything looks ok then click on “Create Auto Scaling group” button.
       10. At the end you will get  below successful message.

(https://snag.gy/BifZIL.jpg)

Now you can able to see that one instance is started running with tag “Auto Scaled Web servers” automatically.

(https://snag.gy/0msyQE.jpg)

Step for increasing CPU utilization:

In real scenario this step in not needed. However for demo we need to increase the CPU utilization so that EC2 will be scaled up automatically.
Code: [Select]
vi /tmp/inc_cpu.sh
and put below lines in the same file as many you can.

Code: [Select]
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
Save and quit file using “:wq!” option. Make the script executable using below command.

Code: [Select]
chmod u+x /tmp/inc_cpu.sh
Now goto /tmp using “cd /tmp” command execute shell script multiple time created so that CPU utilization will increase.

Code: [Select]
nohup ./inc_cpu.sh &
You will notice that CPU utilization will start increasing as below since Idle Utilization is zero:

Code: [Select]
top - 18:06:30 up 34 min,  2 users,  load average: 2.37, 0.70, 0.24
Tasks: 101 total,   5 running,  96 sleeping,   0 stopped,   0 zombie
Cpu(s):  2.0%us, 98.0%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1017372k total,   178292k used,   839080k free,     9016k buffers
Swap:        0k total,        0k used,        0k free,    98176k cached

As a result of this auto scaling policy , one Ec2 instance will be get launched (initialized) automatically (after cooling period of 300 secs) since our threshold of above 30% CPU utilization has passed already .

(https://snag.gy/eVLnjd.jpg)

After some time, once CPU utilization decreases below 20%. In our case idle becomes 100%.

(https://snag.gy/7y1rRw.jpg)

This how we can configure-setup auto scaling in AWS.

 ;)