Tập tành AutoScalingGroup + Application Load Balencer Lab
This lab ask you to create Auto Scaling Group + Application Load Balencer + Target Group on your own.
Prepare
Create your own VPC for simulate the Lab. You can create a new VPC with new feature by one click or do it the old way.
Start the Lab
There are three requirements:
- Create 2 Security group
- First Security Group for ALB which only allow inbound on port 80
- Second Security Group for ASG which only allow traffic from ALB on port 80
- Create ALB
- Internet facing
- Security Group only allow inbound on port 80
-
Target Group with:
- Health check path: index.html
- Create ASG with
- launch configuration:
- Instance type: t3.nano
- Security Group : Only allow traffic from ALB
- User Data
yum update -y amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2 yum install -y httpd mariadb-server systemctl start httpd systemctl enable httpd usermod -a -G apache ec2-user chown -R ec2-user:apache /var/www chmod 2775 /var/www find /var/www -type d -exec chmod 2775 {} \; find /var/www -type f -exec chmod 0664 {} \; echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
- Group Size:
- Minimum and Desired Capacity: 2
- Maximum Capacity : 4
- Create Target Tracking Policy with:
- Average CPU ultilization : 75
- launch configuration:
First requirement:
-
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
-
In the navigation pane, choose Security Groups.
-
Choose Create security group.
-
Create first security group on allow traffic from internet(Source: Anywhere) on port 80
- Create second security group on allow traffic from alb(Source: alb's security group) on port 80
Second requirement:
-
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
-
In the left navigation pane, under Load Balancing, choose Target Groups.
-
Choose Create target group.
-
In the Basic configuration section, select Instance to specify targets by instance ID and enter a name for the target group.
-
Choose your VPC for simulate the Lab
-
In the Health checks section, set the Health check to the target group with HTTP protocol and set the path to /index.php
-
In the navigation pane, under Load Balancing, choose Load Balancers. Choose Application Load Balancer
-
For Load balancer name, enter a name for your load balancer.For Scheme, choose Internet-facing
- For VPC, select the VPC that you used for your EC2 instances. If you selected Internet-facing for Scheme, only VPCs with an internet gateway are available for selection. For Mappings, select two or more Availability Zones and corresponding subnets
- For Security groups, select an existing security group. For Listeners and routing, the default listener accepts HTTP traffic on port 80 and forward to existed Target group that you create before
Third requirement:
-
To create a launch configuration. On the navigation pane, under AUTO SCALING, choose Launch Configurations.
-
Choose Create launch configuration, and enter a name for your launch configuration.
-
For Amazon machine image (AMI) , choose an AMI (The AMI will be specify in the lab, sine i dont remeber it's AMI number so i will pick random). And choose Instance type: t3.micro
- For Advanced details, specify User Data to configure an instance during launch
- For Security groups, select existed security group which only allow traffic from ALB
-
On the navigation pane, under AUTO SCALING, choose Auto Scaling group.
-
On the Choose launch template and select the template that you just create, for Auto Scaling group name, enter a name for your Auto Scaling group.
- On the Configure instance launch options page, under Network, for VPC, choose a VPC. The Auto Scaling group must be created in the same VPC as the security group you specified in your launch configuration. For Availability Zones and subnets, choose one or more subnets in the specified VPC
- To register your Amazon EC2 instances with a load balancer, choose an existing load balancer
- On the Configure group size and scaling policies page, configure the following options:
- Desired capacity: 2
- Minimum capacity: 2
- Maximum capacity: 4
- For Scaling Policies, choose Target tracking scaling policy and set the Metric type to Average CPU Utilization and set the target value to 75
You can check if everything it's ok by go to EC2 Dashboard
At this step you finish the lab