brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Apr 03. 2021

10탄-AWS AutoScaling CLI 실습

CLI로 Auto Scaling 설정해보자

부하 테스트해서 알람이 오는지 확인해보자

부하 테스트해서 잘 증가 되는지 확인해보자



<1> EC2 접속해 role주기

<2> Auto Scaling 시작구성 =  Lanunch config (lc)

<3> Auto Scaling 그룹 만들기  

<4> Auto Scaling에서 생성된 서버  이름(Name)) 주기

<5> 테스트 >  EC2 1개 STOP

<6> 콘솔에서 서버 태그로  확인하기 

<7>  Auto Scaling  알람을 위해   SNS 서비스 설정하기

<8>  Scale Up 정책

<9>  Scale Down 정책 ?

<10> Cloudwatch  High CPU 알람 받기

<11> Cloudwatch Low CPU 알람 받기

<12> EC2 >  Load Balancers  >  DNS >  웹 접속 > Load test 클릭

<13> 확인

<14> AWS CLI 명령어




<1>  EC2 생성, role주기


1

EC2  생성

public에 ec2 만들기


2

ec2-autoscaling-role 을 EC2에 넣음

policy 생성 , role 생성, EC2 


3

aws configure


[ec2-user@ip-10-1-11-50 ~]$ aws configure


AWS Access Key ID [None]: 

AWS Secret Access Key [None]:

Default region name [None]: us-west-2

Default output format [None]:



3

[ec2-user@ip-10-1-11-50 ~]$ ls

as-bootstrap.sh  examplefiles-as.zip


[ec2-user@ip-10-1-11-50 ~]$ more  html-source.sh

#!/bin/sh

yum -y install httpd php mysql php-mysql

chkconfig httpd on

/etc/init.d/httpd start

cd /tmp

wget  https://ssssssss3.amazonaws.com/html-source.zip

unzip html-source.zip

mv html-source/* /var/www/html



<2> Auto Scaling 시작구성 =  Lanunch config (lc)


1

AMIID - 웹서버 ami 1개 만듬

KEYNAME - pem key  autoscaling

EC2SECURITYGROUPID - 보안그룹 80 허용

launch-configuration-name seo-lc


2

aws autoscaling create-launch-configuration --image-id ami-xxxxxx --instance-type t3.micro --key-name autoscaling --security-groups sg-xxxxx --user-data file:///home/ec2-user/html-source.sh --launch-configuration-name seo-lc

// console > EC2 >  Lanunch configuration에서 생성 확인




<3> Auto Scaling 그룹 만들기  


1

auto Scaling 그룹 만들기  ?

LOADBALANCER 

SUBNET1,SUBNET2


classic-lb 하나  pub subnet에 만든다.

seo-au-lb


auto-scaling-group-name seo-auto-group

aunch-configuration-name seo-lc

SUBNET1,SUBNET2


3

aws autoscaling create-auto-scaling-group --auto-scaling-group-name seo-auto-group --launch-configuration-name seo-lc --load-balancer-names seo-au-lb --max-size 4 --min-size 2 --vpc-zone-identifier subnet-1111,subnet-2222222222

// Classic LB를 이용, 다른 LB는 명령어가 틀리다.

// 초기 서버 2대가 생긴다.




<4> Auto Scaling에서 생성된 서버  이름(Name)) 주기


Auto Scaling에서 생성될 서버  이름(Name)을 SEO-Auto-Server1 으로 지정하기  ?


auto-scaling-group-name seo-auo-group


aws autoscaling create-or-update-tags --tags "ResourceId=seo-auto-group, ResourceType=auto-scaling-group, Key=Name, Value=SEO-Auto-Server1, PropagateAtLaunch=true"



<5> 테스트 >  EC2 1개 STOP


1

10분후  서버이름이  달린 서버가 뜬다.

Auto Scaling으로 서버가 뜬것이다.




<6> 콘솔에서 서버 태그로  확인하기 


톱니바퀴 아이콘 >  Tag columes > aws:autoscalingName  체크 해서 

서버 내용 확인하기

태그 네임으로   서버  확인 가능하다.




<7>  Auto Scaling  알람을 위해   SNS 서비스 설정하기


1

서비스 > SNS > 토픽 생성 > 표준

auto-topic

토픽 생성


2

Create subscription 

email

topasvga@naver.com



3

topic > arn 확인

arn:aws:sns:us-west-2:xxxxxxxxxxxxxxxx:auto-topic



auto scaling 알람 생성하기


5

타입 확인

aws autoscaling describe-auto-scaling-notification-types


[ec2-user@ip-10-1-11-94 html]$ aws autoscaling describe-auto-scaling-notification-types

{

    "AutoScalingNotificationTypes": [

        "autoscaling:EC2_INSTANCE_LAUNCH",

        "autoscaling:EC2_INSTANCE_LAUNCH_ERROR",

        "autoscaling:EC2_INSTANCE_TERMINATE",

        "autoscaling:EC2_INSTANCE_TERMINATE_ERROR",

        "autoscaling:TEST_NOTIFICATION"

    ]

}



6

설정

seo-auto-group

ARN 수정


aws autoscaling put-notification-configuration --auto-scaling-group-name seo-auto-group --topic-arn arn:aws:sns:us-west-2:xxxxxxxxxx:auto-topic --notification-types autoscaling:EC2_INSTANCE_LAUNCH autoscaling:EC2_INSTANCE_TERMINATE




<8>  Scale Up 정책


--policy-name seo-scale-up-policy

--auto-scaling-group-name seo-auto-group


aws autoscaling put-scaling-policy --policy-name seo-scale-up-policy --auto-scaling-group-name seo-auto-group --scaling-adjustment 1 --adjustment-type ChangeInCapacity --cooldown 300 --query 'PolicyARN' --output text



<9>  Scale Down 정책 ?


--policy-name seo-scale-down-policy

--auto-scaling-group-name seo-auto-group


aws autoscaling put-scaling-policy --policy-name seo-scale-down-policy --auto-scaling-group-name seo-auto-group --scaling-adjustment -1 --adjustment-type ChangeInCapacity --cooldown 300 --query 'PolicyARN' --output text




<10> Cloudwatch  High CPU 알람 받기


1

CloudWatch

Alarms > Create Alarm >  set metric > ec2    > by auto scaling group >   찾기  cpu  >  체크  


2

> 그래픽 메트릭 > 평균  1분  


아래 

Set metric

Condition > greate  / equal >  30

Sns  추가


3

Notificaton 에서 존재하는 것 선택


4

Auto scaling   action 

add autoscling action 

select a group 


Create 알람



<11> Cloudwatch Low CPU 알람 받기


1

CloudWatch

Alarms > create alarm >  set metric > ec2    > by auto scaling group >   찾기  cpu  >  체크  


2

> 그래픽 매트릭 > 평균  1분  


아래 

 Set metric


3

Condition > lower / equal >  5

Sns  추가


4

Notificaton 에서 존재하는 것 선택


5

Auto scaling   action 

Add autoscling action 

Select a group 


create 알람



<12> EC2 >  Load Balancers  >  DNS >  웹 접속 > Load test 클릭




<13> 확인


aws autoscaling describe-scaling-activities --auto-scaling-group-name seo-auto-group



<14> AWS CLI 명령어


https://docs.aws.amazon.com/autoscaling/index.html




감사합니다.


매거진의 이전글 560. Access Advisor로 권한 회수

작품 선택

키워드 선택 0 / 3 0

댓글여부

afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari