โ๏ธ ๋ฉ๋ชจ๋ฆฌ : 4G
โ๏ธ ์ง๊ธ ์ ๊ฐ์๋จธ์ ๋ง๋ค๊ธฐ
โ๏ธ VDI
โ๏ธ ๋์ ํ ๋น ( ์ค๋ฌด์์๋ ๊ณ ์ ํฌ๊ธฐ)
โ๏ธ 128GB-๋ง๋ค๊ธฐ
โ๏ธ ํ๋กํผ ํด์
โ๏ธCPU 2๊ฐ
โ๏ธ
์ง๋ ฌํฌํธ,๊ณต์ ํด๋,์ฌ์ฉ์์ธํฐํ์ด์ค ์๋ต
-> ์์
โ๏ธ english - Date & Time : seoul - installation destination
โ๏ธ network&host
โ๏ธ installํ๋ค์, rootpassword์
๋ ฅํด์ฃผ๊ธฐ
โ๏ธ rebootํ๊ณ ์๋ ๋ช
๋ น์ด ์งํ
--- CentOS7 ์ค์
# yum install -y bash-completion wget unzip rdate
# rdate -s time.bora.net
# setenforce 0
# sed -i s/^SELINUX=.*$/SELINUX=disabled/ /etc/selinux/config
# cd /tmp
# systemctl disable --now firewalld
# yum update -y
# poweroff
โ๏ธ ํ์ผ - ๊ฐ์์์คํ ๋ด๋ณด๋ด๊ธฐ - centos7์ ํ - ๋ค์ - ๋ค์ - ๋ค์ - ๋ด๋ณด๋ด๊ธฐ ( ํ์ผ๋ช cenOS-vbox.ova๋ก ๋ฐ๊ฟ์ฃผ๊ธฐ ๊ฒฝ๋ก '๋ฌธ์'์ ์ ์ฅ๋์ด์์)
# cd /tmp
# curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
# unzip awscliv2.zip
# ./aws/install
# aws --version
# aws configure
https://docs.aws.amazon.com/cli/latest/reference/
[root@localhost ~] vi .bash_profile
complete -C '/usr/local/bin/aws_completer' aws
โ๏ธ AWS -IAM - ์ฌ์ฉ์ - ์ฌ์ฉ์ ์ถ๊ฐ - ์ฌ์ฉ์ ์ด๋ฆ : mj - ์ก์ธ์ค ํค - ๋ค์
โ๏ธ ๊ธฐ์กด ์ ์ฑ
์ง์ ์ฐ๊ฒฐ - AdministratorAccess - ๋ค์
โ๏ธ ํ๊ทธ ์๋ต- ๋ค์ - ์ฌ์ฉ์ ๋ง๋ค๊ธฐ - .csv ๋ค์ด๋ก๋
โ๏ธ mobaxterm์์ ์ ์,์๋ ๋ช
๋ น์ด ์ด์ฉํ์ฌ CLI์์ ๋ก๊ทธ์ธ
[root@localhost ~]# aws configure
AWS Access Key ID [None]: ์ก์ธ์ค ํค ID ์
๋ ฅ
AWS Secret Access Key [None]: .csv์ด์ด์ secret key ์
๋ ฅ
Default region name [None]: ap-northeast-2
Default output format [None]: json
!--ํ์ธ ์์
--!
[root@localhost ~]# aws s3 ls
# aws ec2 create-vpc --cidr-block 192.168.0.0/16 --tag-specification "ResourceType=vpc,Tags=[{Key=Name,Value=NEW-VPC}]" --output text
!--๊ฒฐ๊ณผ๊ฐ์ vpc id๋ณต์ฌํด์ ์๋์ ๋ฃ๊ธฐ (๋ณ์ ์์ฑ)--!
# NEW_VPC=vpc-0eb8de2efd8ea573d
# echo $NEW_VPC
!--์๋ธ๋ท ์์ฑ ํ JSONํํ์ ๊ฒฐ๊ณผ๊ฐ ์ถ๋ ฅ(A)--!
# aws ec2 create-subnet --vpc-id $NEW_VPC --cidr-block 192.168.0.0/20 --availability-zone ap-northeast-2a --tag-specification "ResourceType=subnet,Tags=[{Key=Name,Value=NEW-PUBLIC-SUBNET-2A}]"
!-- ์๋ธ๋ท ์์ฑ ํ tableํํ์ ๊ฒฐ๊ณผ๊ฐ ์ถ๋ ฅ(B)--!
# aws ec2 create-subnet --vpc-id $NEW_VPC --cidr-block 192.168.16.0/20 --availability-zone ap-northeast-2b --tag-specification "ResourceType=subnet,Tags=[{Key=Name,Value=NEW-PUBLIC-SUBNET-2B}]" --output table
# aws ec2 create-subnet --vpc-id $NEW_VPC --cidr-block 192.168.32.0/20 --availability-zone ap-northeast-2c --tag-specification "ResourceType=subnet,Tags=[{Key=Name,Value=NEW-PUBLIC-SUBNET-2C}]"
# aws ec2 create-subnet --vpc-id $NEW_VPC --cidr-block 192.168.48.0/20 --availability-zone ap-northeast-2d --tag-specification "ResourceType=subnet,Tags=[{Key=Name,Value=NEW-PUBLIC-SUBNET-2D}]"
!--๋ง๋ ๊ฒ ํ์ธ --!
# aws ec2 describe-subnets --filters "Name=vpc-id,Values=$NEW_VPC" --query 'Subnets[*].{AZ:AvailabilityZone,CIDR:CidrBlock}'
# aws ec2 create-internet-gateway --tag-specification "ResourceType=internet-gateway,Tags=[{Key=Name,Value=NEW-IGW}]" --output text
!--๊ฒฐ๊ณผ๊ฐ์ igw id๋ณต์ฌํด์ ์๋์ ๋ฃ๊ธฐ (๋ณ์ ์์ฑ)--!
# NEW_IGW=igw-027e8afbbc878150b
# aws ec2 attach-internet-gateway --vpc-id $NEW_VPC --internet-gateway-id $NEW_IGW
# aws ec2 describe-internet-gateways --output table
# aws ec2 describe-route-tables --filter "Name=vpc-id,Values=$NEW_VPC"
# NEW_RTB=rtb-00b7e49c4988758d4
# aws ec2 create-route --route-table-id $NEW_RTB --destination-cidr-block 0.0.0.0/0 --gateway-id $NEW_IGW
# aws ec2 create-tags --resources $NEW_RTB --tags "Key=Name,Value=NEW-PUBLIC-SUBNET-RTB"
# aws ec2 describe-route-tables --route-table-id $NEW_RTB --output table
# aws ec2 describe-subnets --filters "Name=vpc-id,Values=$NEW_VPC" --query 'Subnets[*].{ID:SubnetId,CIDR:CidrBlock}'
!--๊ฒฐ๊ณผ๊ฐ์ subnet id๋ณต์ฌํด์ ์๋์ ๋ฃ๊ธฐ (๋ณ์ ์์ฑ)--!
# NEW_SID1=subnet-0513c8a4fa9377070
# NEW_SID2=subnet-04cfef78ec33e5e5f
# NEW_SID3=subnet-0ba09b125dd7b36d1
# NEW_SID4=subnet-0d71da42aad4e3515
# aws ec2 associate-route-table --subnet-id $NEW_SID1 --route-table-id $NEW_RTB
# aws ec2 associate-route-table --subnet-id $NEW_SID2 --route-table-id $NEW_RTB
# aws ec2 associate-route-table --subnet-id $NEW_SID3 --route-table-id $NEW_RTB
# aws ec2 associate-route-table --subnet-id $NEW_SID4 --route-table-id $NEW_RTB
!-- ํผ๋ธ๋ฆญ IP์ฃผ์ ์๋ ํ ๋น ํ์ฑํ --!
# aws ec2 modify-subnet-attribute --subnet-id $NEW_SID1 --map-public-ip-on-launch
# aws ec2 modify-subnet-attribute --subnet-id $NEW_SID2 --map-public-ip-on-launch
# aws ec2 modify-subnet-attribute --subnet-id $NEW_SID3 --map-public-ip-on-launch
# aws ec2 modify-subnet-attribute --subnet-id $NEW_SID4 --map-public-ip-on-launch
!-- ํผ๋ธ๋ฆญdns๊ธฐ๋ฅํ์ฉ --!
# aws ec2 modify-vpc-attribute --vpc-id $NEW_VPC --enable-dns-hostnames
# aws ec2 create-key-pair --key-name new-key --query 'KeyMaterial' --output text > new-key.pem
# chmod 400 new-key.pem
# aws ec2 create-security-group --group-name NEW-SG-WEB --description "Security group for HTTP_SSH access" --vpc-id $NEW_VPC
!--๊ฒฐ๊ณผ๊ฐ์ subnet id๋ณต์ฌํด์ ์๋์ ๋ฃ๊ธฐ (๋ณ์ ์์ฑ)--!
# NEW_SG=sg-0116cd5ea641b5cd2
# aws ec2 authorize-security-group-ingress --group-id $NEW_SG --protocol tcp --port 22 --cidr 0.0.0.0/0
or
cidr 123.142.252.25/32 ( ๊ฐ์์ค์์๋ง ์ ์ ๊ฐ๋ฅ - ๋ณด์ ๊ฐํ)
# aws ec2 authorize-security-group-ingress --group-id $NEW_SG --protocol tcp --port 80 --cidr 0.0.0.0/0
# aws ec2 authorize-security-group-ingress --group-id $NEW_SG --protocol icmp --port -1 --cidr 0.0.0.0/0
# vi mapping.json
[
{
"DeviceName": "/dev/xvda",
"Ebs": {
"VolumeSize": 8
}
},
{
"DeviceName": "/dev/xvdb",
"Ebs": {
"VolumeSize": 8
}
}
]
# vi my_script.txt
#!/bin/bash
yum install -y httpd
systemctl enable --now httpd
echo "<h1>Hello AWS CLI</h1>" > /var/www/html/index.html
# aws ec2 run-instances \
--image-id ami-0fd0765afb77bcca7 \
--count 1 \
--instance-type t2.micro \
--key-name new-key \
--security-group-ids $NEW_SG \
--subnet-id $NEW_SID1 \
--block-device-mappings file://mapping.json \
--user-data file://my_script.txt \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=NEW-WEB}]' 'ResourceType=volume,Tags=[{Key=Name,Value=NEW-ROOT}]'
!--๊ฒฐ๊ณผ๊ฐ์ InstanceId"๋ณต์ฌํด์ ์๋์ ๋ฃ๊ธฐ (๋ณ์ ์์ฑ)--!
# NEW_IID=i-0f9227878ecf00546
# aws ec2 describe-instances --instance-id $NEW_IID | grep PublicIp
!--๊ฒฐ๊ณผ๊ฐ์ IP๋ณต์ฌํด์ ์๋์ ๋ฃ๊ธฐ (๋ณ์ ์์ฑ)--!
# ssh -i "new-key.pem" ec2-user@3.34.191.74
# curl 3.34.191.74
โ๏ธ ์ถ๊ฐํ ๋ธ๋กํ ๋ฆฌ์ง ์ฐ๊ฒฐํ๊ธฐ - ํฌ๋งท
โ๏ธ ์ถ๊ฐํ ๋ธ๋กํ ๋ฆฌ์ง ์ฐ๊ฒฐํ๊ธฐ - ๋ง์ดํธ
# aws ec2 terminate-instances --instance-id $NEW_IID
# aws ec2 delete-security-group --group-id $NEW_SG
# aws ec2 delete-subnet --subnet-id $NEW_SID1
# aws ec2 delete-subnet --subnet-id $NEW_SID2
# aws ec2 delete-subnet --subnet-id $NEW_SID3
# aws ec2 delete-subnet --subnet-id $NEW_SID4
# aws ec2 detach-internet-gateway --internet-gateway-id $NEW_IGW --vpc-id $NEW_VPC
# aws ec2 delete-internet-gateway --internet-gateway-id $NEW_IGW
# aws ec2 delete-vpc --vpc-id $NEW_VPC
โ๏ธ 1. IaC (Infrastructure as Code ) - ๊ตฌ์ฑ ๋ฐ ์ค์ ์๋ํ - Terraform, Ansible
โ๏ธ 2. Container ๊ธฐ์ ๋ฐ ์ค์ผ์คํธ๋ ์ด์
- Docker, Kubernetes
โ๏ธ 3. CI/CD (Continuous Integeration/ Continuous Deployment(Delivery))- Jenkins,Git, Gitlab
[root@localhost ~]# date
Wed Jun 29 11:07:17 KST 2022
[root@localhost ~]# timedatectl
Local time: Wed 2022-06-29 11:07:23 KST
Universal time: Wed 2022-06-29 02:07:23 UTC
RTC time: Wed 2022-06-29 02:07:18
Time zone: Asia/Seoul (KST, +0900)
NTP enabled: n/a
NTP synchronized: no
RTC in local TZ: no
!--ํ์์กด ์ค์ ๋ช
๋ น์ด --!
# timedatectl set-timezone Asia/Seoul
https://docs.aws.amazon.com/cli/latest/reference/
[root@localhost ~]# ls .aws
config credentials
[root@localhost ~]# cat .aws/config
[default]
region = ap-northeast-2
output = json
[root@localhost ~]# vi .aws/config
[root@localhost ~]# cat .aws/config
[default]
region = ap-northeast-1
output = table
[root@localhost ~]# cat .aws/credentials
์์ key id์ key ์์. ๋ณด์ ์๊ฐํ๋ฉด ์ข ๋ฃํ ๋ ์ด ํ์ผ ์ง์ฐ๋ ๊ฒ์ด ์ข์.