AWS 정리 (2) - EC2 / Auto Scaling / ELB

임쿠쿠·2022년 2월 12일
0

AWS 기초

목록 보기
2/6
post-thumbnail

EC2

1) Summury

  • EC2 hosts are managed by AWS
  • An EC2 instance is a virtual server
  • EC2 instances run Windows or Linux OS

2) Public, Private, and Elastic IP addresses

(1) Public IP address

  • Lost when the instance is stopped
  • Used in Public subnets
  • No charge
  • Asscociated with a private IP address on the instance
  • Cannot be moved between instances

(2) Private IP address

  • Retained when the instance is stopped
  • Used in Public and Private Subnets

(3) Elastic IP address

  • Static Public IP address
  • You are charged if not used
  • Asscociated with a private IP address on the instance
  • Can be moved between instances and Elastic Network Adapters

3) Public, Privage Subnets

(1) Public Subnet

  • Public IP or Elastic IP is attached an EC2 instance and away out Internet by Internet gateway

(2) Private Subnet

  • NAT Gateway forwards connections to the Internet
    프라이빗 서브넷에 있는 EC2 인스턴스는 프라이빗 IP만 가질 수 있고, 인터넷과 연결하려면 NAT gateway로 전송 후 퍼블릭 서브넷의 퍼블릭 IP로 인터넷 게이트웨이로 송신

4) Launching an Amazon EC2 Instance

(1) AMI 선택

(2) 인스턴스 유형 선택

... 중략
(3) 키페어 생성

(4) 연결

(5) 웹서버 테스트

#!/bin/bash
yum update -y
yum install httpd -y
systemctl start httpd
systemctl enable httpd
cd /var/www/html
echo "This is a test page on EC2" > index.html

  • 사용자 데이터 추가

  • 인바운드 규칙 편집

5) Using IAM Roles with EC2

EC2 인스턴스와 S3 버킷 연결

(1) 역할 생성

(2) 정책 설정

(3) EC2 역할 연결

(4) 테스트

6) Scale Elastically with Amazon EC2 Auto Scaling

(1) EC2 인스턴스 중 하나가 fail이 나면 Auto Scaling Group이 새로운 인스턴스 생성
(2) Metric 기록 중 CPU 사용률이 높으면, CloudWatch에게 알리고 CloudWatch는 ASG에게 스케일 작업 요청, 이후 ASG에서 여분의 인스턴스를 런칭

Auto Scaling Group Practice

(1) ASG 명 설정

(2) 시작 템플릿 생성

템플릿 콘텐츠 생성

인스턴스 유형 설정

네트워크 설정

(3) ASG 생성

키페어 설정

그룹 크기 설정

(4) 테스트

  • 그룹 크기에 따른 3개의 인스턴스 자동 생성
  • 수동으로 teminate 시, 3개까지 자동 생성

7) Create a Target Tracking Scaling Policy

CPU 사용률 증가 Command

sudo amazon-linux-extras install epel -y
sudo yum install stress -y
stress -c 8

결과

  • Cpu 사용률 증가에 따른 인스턴스 증가

8) Add Load Balancing with Amazon ELB

인스턴스 fail 경우

  • ELB의 Health Check를 통해 사용자의 요청을 다른 인스턴스로 연결
  • EC2 Auto Scaling을 통해 해당 인스턴스를 종료
  • 새로운 인스턴스 런칭

#!/bin/bash
yum update -y
yum install httpd -y
systemctl start httpd
systemctl enable httpd
cd /var/www/html
aws s3 cp s3://YOUR-BUCKET-NAME/names.csv ./
aws s3 cp s3://YOUR-BUCKET-NAME/index.txt ./
EC2NAME=cat ./names.csv|sort -R|head -n 1|xargs
sed "s/INSTANCEID/$EC2NAME/" index.txt > index.html

ALB Practice

(1) 로드밸런서

네트워크 매핑 설정

보안 그룹 설정

리스너 설정

(2) S3

(3) 템플릿 생성

권한 설정

사용자 데이터

(3) ASG 생성

로드밸런서 연결

(4) 결과

  • 4개의 인스턴스 생성 및 로드밸런서에 의해 새로고침 시 4개의 인스턴스에 연결

참고 - AWS Basics / Digital Cloud Training

profile
Pay it forward

0개의 댓글