궁금한게 많은 개발자 노트

[ AWS ] EC2 Instance basic 본문

DevOps

[ AWS ] EC2 Instance basic

궁금한게 많은 개발자 2022. 10. 9. 21:59

EC2: Elastic Compute Cloud = infrastructure as a Service

AWS Service들중 가장 많이 사용되는 service이다. 단지 하나의 서비스인 것이 아니라, 여러 것들의 복합 서비스이다.

주로 다음과 같은 기능들로 구성됩니다.

Renting virtual machines (EC2)

Stroring data on virtual drives (EBS: Elastic Block Store)

Distribute load across machines(ELB: Elastic Load Balancer)

Scale service using an auto-scaling group or ASG(Auto Scaling Groups) 

 

즉, EC2를 이해하는 것은 클라우드의 동작 방식을 이해하는 데 기본입니다.

the cloud is to be able to rent these compute whenever you need, on demand, and EC2 is just that.

 

EC2 Configuration : OS, CPU, RAM, Storage Space(Network-attached(EBS&EFS), Hardware(EC2 Instance Store)), Network card: speed of the card, public IP address, Firewall rules: security group, Bootstrap script (Configure at first launch): EC2 User Data

 

 

EC2 USer Data

부트스트랩은 EC2 인스턴스를 AWS가 내부적으로 생성하면서 초기에 EC2가 수행할 명령을 미리 지정하는 것을 의미한다. 주로 운영 체제의 패치, 모듈의 설치 혹은 업데이트를 진행할 때 사용한다.

ex) 업데이트 설치, 소프트웨어 설치, 인터넷으로 부터 common 파일들을 다운로드, 부트 타임에 필요한 무엇이든 수행

EC2 instance를 빠르게 셋팅/실행 해주는 User Data script를 의미 (instance가 시작할 때 한번만 수행 됨)

• bootstrapping means launching commands when a machine starts)

automate boot tasks, hence the name bootstrapping, and EC2 User Data Script runs with root user (pseudo rights)

 

# 사용자 데이터 스크립트는 처리 시 /var/lib/cloud/instances/instance-id/에서 복사 및 실행됩니다. 스크립트는 실행 후에는 삭제가 되지 않습니다. 용자 데이터로 입력된 스크립트는 root 사용자 권한으로 실행되므로 스크립트에 sudo 명령을 사용하지 마세요. 생성하는 모든 파일의 소유권은 root에 있습니다. 루트 이외의 사용자에게 파일 액세스를 허용하려면 스크립트에서 권한을 적절히 수정해야 합니다. 또한 스크립트는 대화형으로 실행되지 않으므로 사용자의 입력이 필요한 명령(예: yum update 플래그 없는 -y)은 포함할 수 없습니다.

#!/bin/bash
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
...

 

 

EC2 instance types

AWS에는 EC2 instance의 naming convention이 존재합니다.

ex) instance type-generation.size within the instance class(more size, more memory, more cpu..) https://instances.vantage.sh/

General Purpose: 웹서버나 코드 레포 등의 다양한 workload에 적합하고, Compute, Memory, Networking 밸런스 좋음

Compute Optimzied: compute-intensive task들에 적합 (high performance processors) - c로 시작하는 instance class

ex) Batch processing workloads • Media transcoding • High performance web servers • High performance computing (HPC) • Scientific modeling & machine learning • Dedicated gaming servers

Memory Optimized: memory에 있는 많은 데이터를 처리하는 workload를 위한 빠른 성능을 지원

ex) • High performance, relational/non-relational databases • Distributed web scale cache stores • In-memory databases optimized for BI (business intelligence) • Applications performing real-time processing of big unstructured data

Storage Optimized: storage-intensive task들에 적합 (high, sequential read/write access to large data sets on local storage) ex) High frequency online transaction processing (OLTP) systems • Relational & NoSQL databases • Cache for in-memory databases (for example, Redis) • Data warehousing applications • Distributed file systems

 

 

 

EC2 Instance Key Pair(login)

퍼블릭 키와 프라이빗 키로 구성되는 키 페어는 Amazon EC2 인스턴스에 연결할 때 자격 증명 입증에 사용하는 보안 자격 증명 집합입니다. Amazon EC2는 퍼블릭 키를 인스턴스에 저장하며 프라이빗 키는 사용자가 저장합니다. Linux 인스턴스의 경우 프라이빗 키를 사용하여 인스턴스에 안전하게 SSH로 연결할 수 있습니다.

 

프라이빗 키를 소유하는 사람은 누구나 인스턴스에 연결할 수 있으므로 보안된 위치에 프라이빗 키를 저장해 두는 것이 중요합니다. 인스턴스를 시작할 때 키 페어를 입력하라는 메시지가 표시됩니다. SSH를 사용하여 인스턴스에 연결하려는 경우 키 페어를 지정해야 합니다. 기존 키 페어를 선택하거나 새로 만들 수 있습니다. 인스턴스가 처음 부팅될 때 시작 시 지정한 퍼블릭 키가 Linux 인스턴스에 있는 ~/.ssh/authorized_keys 내 항목에 배치됩니다. SSH를 사용하여 Linux 인스턴스에 연결할 때 로그인하려면 퍼블릭 키에 해당하는 프라이빗 키를 지정해야 합니다. 참고로 Amazon EC2에는 프라이빗 키의 사본이 보관되지 않으므로, 프라이빗 키를 분실하면 이를 복구할 방법이 전혀 없으므로 주의해야 합니다.

SSH 클라이언트를 이용하여 Linux 인스턴스 연결 방법

 

SSH를 사용하여 Linux 인스턴스에 연결 - Amazon Elastic Compute Cloud

이 페이지에 작업이 필요하다는 점을 알려 주셔서 감사합니다. 실망시켜 드려 죄송합니다. 잠깐 시간을 내어 설명서를 향상시킬 수 있는 방법에 대해 말씀해 주십시오.

docs.aws.amazon.com

 

 

[ EC2 Summary ]

EC2 Instance: AMI(OS) + Instance size (CPU + RAM) + Storage + Security groups + EC2 User data

Security Group: Firewall attached to the EC2 instance = 방화벽

EC2 User data: script launched at the first start of an instance

SSH: start a terminal into our EC2 instance

EC2 instance role: link to IAM roles

 

 

'DevOps' 카테고리의 다른 글

[ AWS ] EC2 instance connect with SSH  (0) 2022.10.20
[ AWS ] EC2 Security Groups  (0) 2022.10.12
[ AWS ] IAM Permissions  (0) 2022.10.07
[ AWS ] Cloud Overview  (0) 2022.10.06
[ AWS ] Cloud Computing  (0) 2022.10.03
Comments