10週目-4つの自動スケーリンググループを使用してWebSVSを構成
最終構成

EC 2->EC 2起動テンプレートの作成->次の内容を入力し、
시작 템플릿 생성
をクリックします.시작 템플릿 이름 : WPEC2LaunchTemplate
설명 : Wordpress Web Auto Scaling v1.0
Auto Scaling 지침 : 체크
AMI : Amazon Linux 2 AMI(HVM), SSD Volume Type - 아키텍처 : 64비트(x86)
인스턴스 유형 : t2.micro
키 페어 : (각자 자신의 SSH 키페어 선택)
네트워킹 플랫폼 : VPC
보안 그룹 : ###-WP-VPC1SG-### 포함된것 선택
리소스 태그 : 키(Lab) , 값(WPLab)
고급 세부 정보 ← 클릭
- IAM 인스턴스 프로파일 : WPLabInstanceProfile
- 세부 CloudWatch 모니터링 : 활성화
- 사용자 데이터 : 아래 내용 복붙!
以下のEFSを使用する場合は、それぞれのEFSファイルシステムIDに変更してください#!/bin/bash
amazon-linux-extras install lamp-mariadb10.2-php7.2 php7.2 -y
yum install httpd htop amazon-efs-utils tree -y
systemctl start httpd && systemctl enable httpd
yum install gcc php-xml php-mbstring php-sodium php-devel php-pear ImageMagick-devel ghostscript -y
cat <<EOT> /etc/php.d/40-imagick.ini
extension = imagick.so
EOT
printf "\n" | pecl install imagick
sed -i 's/^upload_max_filesize = 2M/upload_max_filesize = 64M/g' /etc/php.ini
sed -i 's/^post_max_size = 8M/post_max_size = 64M/g' /etc/php.ini
sed -i 's/^max_execution_time = 30/max_execution_time = 300/g' /etc/php.ini
sed -i 's/^memory_limit = 128M/memory_limit = -1/g' /etc/php.ini
mkdir -p /var/www/wordpress/
mount -t efs 자신의EFS파일시스템ID:/ /var/www/wordpress
chown -R apache:apache /var/www
chmod 2775 /var/www
find /var/www -type d -exec chmod 2775 {} \;
find /var/www -type f -exec chmod 0664 {} \;
chmod u+wrx /var/www/wordpress/wp-content/*
echo 'ServerName 127.0.0.1:80' >> /etc/httpd/conf.d/MyBlog.conf
echo 'DocumentRoot /var/www/wordpress' >> /etc/httpd/conf.d/MyBlog.conf
echo '<Directory /var/www/wordpress>' >> /etc/httpd/conf.d/MyBlog.conf
echo ' Options Indexes FollowSymLinks' >> /etc/httpd/conf.d/MyBlog.conf
echo ' AllowOverride All' >> /etc/httpd/conf.d/MyBlog.conf
echo ' Require all granted' >> /etc/httpd/conf.d/MyBlog.conf
echo '</Directory>' >> /etc/httpd/conf.d/MyBlog.conf
systemctl restart php-fpm
systemctl restart httpd
作成された起動テンプレート[
시작 템플릿 생성
]をクリックします.
시작 템플릿 이름 : WPEC2LaunchTemplate
설명 : Wordpress Web Auto Scaling v1.0
Auto Scaling 지침 : 체크

AMI : Amazon Linux 2 AMI(HVM), SSD Volume Type - 아키텍처 : 64비트(x86)
인스턴스 유형 : t2.micro
키 페어 : (각자 자신의 SSH 키페어 선택)

```bash
ネットワークプラットフォーム:VPC
安全グループ:###-WP-VPC 1 SG-##選択済み
```

```bash
リソースラベル:キー(Lab)、値(WPlab)
```

IAM 인스턴스 프로파일 : WPLabInstanceProfile
세부 CloudWatch 모니터링 : 활성화
사용자 데이터 : 아래 내용 복붙!
以下のEFSを使用する場合は、それぞれのEFSファイルシステムIDに変更してください#!/bin/bash
amazon-linux-extras install lamp-mariadb10.2-php7.2 php7.2 -y
yum install httpd htop amazon-efs-utils tree -y
systemctl start httpd && systemctl enable httpd
yum install gcc php-xml php-mbstring php-sodium php-devel php-pear ImageMagick-devel ghostscript -y
cat <<EOT> /etc/php.d/40-imagick.ini
extension = imagick.so
EOT
printf "\n" | pecl install imagick
sed -i 's/^upload_max_filesize = 2M/upload_max_filesize = 64M/g' /etc/php.ini
sed -i 's/^post_max_size = 8M/post_max_size = 64M/g' /etc/php.ini
sed -i 's/^max_execution_time = 30/max_execution_time = 300/g' /etc/php.ini
sed -i 's/^memory_limit = 128M/memory_limit = -1/g' /etc/php.ini
mkdir -p /var/www/wordpress/
mount -t efs **자신의EFS파일시스템ID**:/ /var/www/wordpress
chown -R apache:apache /var/www
chmod 2775 /var/www
find /var/www -type d -exec chmod 2775 {} \;
find /var/www -type f -exec chmod 0664 {} \;
chmod u+wrx /var/www/wordpress/wp-content/*
echo 'ServerName 127.0.0.1:80' >> /etc/httpd/conf.d/MyBlog.conf
echo 'DocumentRoot /var/www/wordpress' >> /etc/httpd/conf.d/MyBlog.conf
echo '<Directory /var/www/wordpress>' >> /etc/httpd/conf.d/MyBlog.conf
echo ' Options Indexes FollowSymLinks' >> /etc/httpd/conf.d/MyBlog.conf
echo ' AllowOverride All' >> /etc/httpd/conf.d/MyBlog.conf
echo ' Require all granted' >> /etc/httpd/conf.d/MyBlog.conf
echo '</Directory>' >> /etc/httpd/conf.d/MyBlog.conf
systemctl restart php-fpm
systemctl restart httpd


[
시작 템플릿 생성
]をクリックします.
タスクをクリックします->
Auto Scaling 그룹 생성

Auto Scaling 그룹 이름 : FirstEC2AutoScalingGroup
시작 템플릿 : WPEC2LaunchTemplate

[
다음
]をクリックします.
인스턴스 구매 옵션 : 시작 템플릿 준수
네트워크 - VPC : WP-VPC1
네트워크 - 서브넷 : WP-VPC1-Subnet-1, WP-VPC1-Subnet-2
[다음
]をクリックします.

로드 밸런싱 : 기존 로드 밸런서에 연결
로그 밸런서 대상 그룹에서 선택 : 선택
기존 로드 밸런서 대상 그룹 : ALB-TG
상태 확인 유형 : ELB (Check)
상태 확인 유예 기간 : 60초
모니터링 - CloudWatch 내에서 그룹 지표 수집 활성화 : 체크

[
다음
]をクリックします.
원하는 용량 : 2
최소 용량 : 2
최대 용량 : 4
조정 정책 : 대상 추척 조정 정책
조정 정책 이름 : Scale Out Policy
대상 값 : 30 → 3분 동안 3번 연속 CPU 30% 경우(1분 마다 기록)
인스턴스 요구 사항 : 60초 → 지표에 포함하기 전 워밍업 시간(초)
확대 정책만 생성하려면 축소 비활성화 : Check → 축소 설정하지 않음
인스턴스 축소 보호 활성화 : UnCheck


[
다음
]をクリックします.
[
다음
]をクリックします.
태그 : 키(Name) , 값(WebServers)
[다음
]をクリックします.
[
AutoScaling 그룹 생성
]をクリックします.
2つのEC 2が作成されました


word pressサイトにも接続できます.

CPU負荷と自動スケーリングの確認
# 웹 접속 테스트 (리전, 인스턴스ID, Private IP)
WPDNS=cloudfront.net
Web1=퍼블릭 주소
Web2=퍼블릭 주소
# 터미널1 - 1개 요청(풀)로 총합 500번 요청 진행
ab -n 500 -c 1 http://$Web1/load.php
# 터미널2 - 20개 요청(풀)로 총합 1000번 요청 진행
ab -n 1000 -c 20 http://$Web2/load.php
ab -n 1000 -c 20 http://$WPDNS/load.php
# 접속 되는 EC2 마다 현재 CPU 부하 출력
while true; do curl $WPDNS/xff.php --silent --connect-timeout 1; date; echo "---[AutoScaling]---"; sleep 1; done
# EC2 증가 이후 증감 확인
for i in {1..100}; do curl $WPDNS/xff.php --silent;echo ; done | sort | uniq -c | sort -nr


新しく作成された2つのEC 2がALBターゲットグループに含まれています






EC 2を4つに追加

CPU使用率の比較

1時間に変更

君はこんなに変わった


EC 2を4つに追加

ターゲットグループにも含める

EC 2でも見ることができます.
for i in {1..100}; do curl $WPDNS/xff.php --silent;echo ; done | sort | uniq -c | sort -n

参考資料:AFOS[2期]活動内容
Reference
この問題について(10週目-4つの自動スケーリンググループを使用してWebSVSを構成), 我々は、より多くの情報をここで見つけました https://velog.io/@icebear2n2/10주차-4-AutoScaling-그룹을-이용하여-WebSrvs-구성テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol