수업 46일차 AWS CodeDeploy , Github

유동우·2022년 11월 20일
1

■ 이번 수업 시간

CodeDeploy 역할 생성 -> exercise-instance 시작 후 수정(새로운 코드)
-> AMI(image) -> 시작템플릿 -> Auto scaling 실행 -> 코드 설치

※ 새로운 코드 -> CodeDeploy Agent
AMI 생성하기전에 CodeDeploy Agent가 있어야함.

===========================

■ CodeDeploy를 위한 서비스 역할 생성

보안 자격 증명 -> 역할 -> 역할 생성

AWS 서비스
사용사례 - CodeDeploy - 다음

aws08-exercise-code-deploy-service-role - 생성

■ EC2 인스턴스 역할, 인스턴스 프로파일 생성

보안 자격 증명 -> 정책 -> 정책 생성

JSON 탭 선택

{

"Version": "2012-10-17",
"Statement": [
    {
        "Action": [
            "s3:Get*",
            "s3:List*"
        ],
        "Effect": "Allow",
        "Resource": "*"
        
    }
]

}

※ JSON 문법

JSON 데이터는 쉼표,로 나열됨.
객체는 중괄호{}로 둘러쌓아 표현
배열은 대괄호[]로 둘러쌓아 표현

태그 추가 - Name / aws08-exercise-code-deploy-ec2-policy

aws08-exercise-code-deploy-ec2-policy
Custom policy for EC2 and CodeDeploy
정책생성

역할 생성 - EC2 체크 - 다음
aws08-exercise-code-deploy-ec2-role - 역할 생성

aws08-exercise-code-deploy-ec2-role
인스턴스 프로파일 ARN :
arn:aws:iam::257307634175:role/aws08-exercise-code-deploy-ec2-role

========================================

code-deploy-role : CodeDeploy 권한을 가진 역할

code-deploy-ec2-policy : EC2에서 s3에 접근하는 권한을 가진 정책

code-deploy-ec2-role : code-deploy-ec2-policy 정책을 가진 역할

=========================================

■ CodeDeploy로 배포 가능한 인스턴스 생성하기

EC2에 exercise-instance 연결해서
cd /var/www/
ls
rm -rf aws-exercise-*
wget https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
chmod +x ./install
sudo yum install ruby -y
sudo ./install auto
sudo service codedeploy-agent status
인스턴스 중지

인스턴스에 이미지생성누르고
aws08-exercise-image-code-deploy 생성

시작 템플릿 생성
aws08-exercise-launch-template-code-deploy
code deploy version
원본템플릿에
aws08-exercise-launch-template
이미지는 내 AMI들어가서
aws08-exercise-image-code-deploy
태그 Name / aws08-exercise-launch-template-code-deploy
고급 세부 정보 aws08-exercise-code-deploy-ec2-role삽입
생성

Auto Scaling
만들어뒀던 EXERCISE-GROUP의 편집
시작템플릿값을 aws08-exercise-launch-template-code-deploy으로 변경
이때 버전이 맞는지 확인하고 맞춰줘야됨.
용량 3으로 설정변경해주고
인스턴스 3개인지 확인

=========================================

■ CodeDeploy 애플리케이션 생성

CodeDeploy 서비스 검색
애플리케이션 생성
aws08-exercise
EC2/온프레미스
생성

배포그룹생성
aws08-production-in_place
aws08-exercise-code-deploy-service-role
환경구성
aws08-EXERCISE-GROUP
배포설정
CodeDeployDefault.OneAtATime
대상그룹
aws08-exercise-target-group
생성
배포생성

※ CodeDeployDefault.OneAtATime : 한 번에 하나
CodeDeployDefault.HalfAtATime : 절반씩
CodeDeployDefault.AllAtonce : 한꺼번에

배포설정
애플리케이션을 GitHub에저장하고
GitHub토큰이름 Ryu-dongwoo
연결
커밋ID를 받아오기위해
https://github.com/deopard/aws-exercise-a/tree/code-deploy에 접속
code-deploy 브랜치 복사해서
리포지토리 이름 : deopard/aws-exercise-a
커밋ID : 84f927f9598d0b821cf5e876e3bc7f61d040d8f4
배포설명
first code deploy version
배포만들기

aws08-exercise애플리케이션에서
배포 만들기
GitHub토큰이름 Ryu-dongwoo
연결
커밋ID를 받아오기위해
https://github.com/deopard/aws-exercise-a/tree/code-deploy에 접속
code-deploy 브랜치 v2복사해서
리포지토리 이름 : deopard/aws-exercise-a
커밋ID : bee258b2f5dfaf8aed4139aadce777ea46027ea6
배포만들기

=============================

■ busanit를 git 로컬저장소로 만듬

mkdir busanit
cd busanit
git init
sudo apt install tree -y

cd .git
ls
tree

■ GitHub 접속용 SSH 키 만드는방법

$ cd ~/.ssh
$ ls

$ ssh-keygen -t ed25519 -C "cjstkehddn11@naver.com"
client
enter
enter

■ 공개키를 GitHub 계정에 등록하기

git가서 settings
SSH and GPG keys에 New SSH key
client_Access
ssh가서 cat client.pub
출력값 복사해서
key값에 넣기

■ SSH 접속 설정

chmod 600 config
vim config

아래에 추가하기
Host github.com
User git
IdentityFile ~/.ssh/client
저장하고 나와서
chmod 400 config

ssh -T git@github.com
yes

■ GitHub에 SSH 키로 접속 테스트

git config --global user.name "ryu-dongwoo"
git config --global user.email "cjstkehddn11@naver.com"
cd
cd busanit
git remote add origin git@github.com:Ryu-dongwoo/Sample.git
git remote -v

※ 참고 : https://www.lainyzine.com/ko/article/creating-ssh-key-for-github/

===================

echo "Hello~" >> a.txt
git status
git add a.txt
git status
git commit -m "a.txt upload"
git status

git branch -M main
git status

git log
git push origin +main

※ 확인명령어

git config --global user.name // user.name 확인
git config --global user.email // user.email 확인
git remote -v // remote 저장소 확인

※ 수정시 제거명령어

git config --global --unset user.name "ryu-dongwoo"
git config --global --unset user.email "cjstkehddn11@naver.com"
git remote rm origin

profile
클라우드 엔지니어가 되고싶은 클린이

0개의 댓글