kosmo138 / resumate

자기소개서를 세상에서 가장 쉽게 쓰는 방법
https://www.resumate.store
0 stars 0 forks source link

EC2 배포 환경 준비 #83

Closed suyons closed 3 months ago

suyons commented 3 months ago

작업 개요

  1. CI/CD 파이프라인 구축은 Jenkins 또는 GitHub Actions에 대한 러닝 커브가 있음.
  2. 시간이 부족하므로 로컬 PC에서 EC2 인스턴스로 직접 SSH 연결하여 git clone을 통해 소스 코드 다운로드
  3. .gitignore에 의해 제외된 파일은 FileZilla 이용, SFTP 연결하여 전송

환경 준비

SSH 프로토콜 허용 및 연결

EC2의 보안 그룹에서 SSH 접속하려는 IP 주소의 TCP 22 인바운드를 허용하는 정책 설정을 확인

Image

SSH 연결이 정상적으로 이루어지는지 확인

ssh -i '/path/to/keyfile/key.pem' ubuntu@43.200.244.35

SSH 연결이 정상적으로 이루어졌다면 Shell이 다음과 같이 표시된다.

young@Sooyoung-Mac AWS % sh connect-ec2.sh 

Last login: Fri Apr 12 21:58:04 2024 from 39.115.214.146
ubuntu@ip-172-31-4-70:~$ 

VS Code에서 SSH 연결하기

확장 프로그램 설치: Remote - SSH

실행: > Remote-SSH: Connect to Host - Add New SSH Host - 이후 위의 ssh 실행 명령어 전체 붙여넣기

다음과 같이 원격의 EC2 인스턴스에 로컬과 같이 접근할 수 있다.

Image

오류 1: github.com 접근 불가

git clone을 시도했을 때 호스트를 해석할 수 없다는 오류 메시지를 확인했다. DNS 서버가 특정되어 있지 않아서 github.com 도메인 이름을 해석할 수 없다고 판단했다.

root@ip-172-31-4-70:/home/ubuntu# git clone https://github.com/kosmo138/resumate
Cloning into 'resumate'...
fatal: unable to access 'https://github.com/kosmo138/resumate/': Could not resolve host: github.com

로컬 PC에서의 Ping 테스트 결과는 정상이었다.

young@Sooyoung-Mac ~ % ping www.github.com
PING github.com (20.200.245.247): 56 data bytes
64 bytes from 20.200.245.247: icmp_seq=0 ttl=114 time=17.011 ms
64 bytes from 20.200.245.247: icmp_seq=1 ttl=114 time=18.262 ms
64 bytes from 20.200.245.247: icmp_seq=2 ttl=114 time=8.317 ms
64 bytes from 20.200.245.247: icmp_seq=3 ttl=114 time=27.091 ms
^C
--- github.com ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 8.317/17.670/27.091/6.652 ms

반면, EC2에서의 Ping 테스트 결과는 실패였다.

root@ip-172-31-4-70:/home/ubuntu# ping www.github.com
ping: www.github.com: Temporary failure in name resolution

EC2 인스턴스에서 도메인 네임이 아닌 IPv4 주소로 Ping 테스트를 진행한 결과는 정상이었다.

root@ip-172-31-4-70:/home/ubuntu# ping 20.200.245.247
PING 20.200.245.247 (20.200.245.247) 56(84) bytes of data.
64 bytes from 20.200.245.247: icmp_seq=1 ttl=103 time=2.60 ms
64 bytes from 20.200.245.247: icmp_seq=2 ttl=103 time=2.62 ms
64 bytes from 20.200.245.247: icmp_seq=3 ttl=103 time=2.78 ms
64 bytes from 20.200.245.247: icmp_seq=4 ttl=103 time=2.56 ms
^C
--- 20.200.245.247 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 2.560/2.639/2.780/0.083 ms

호스트 파일에 도메인 네임 매핑을 직접 추가했다.

root@ip-172-31-4-70:/home/ubuntu# vim /etc/hosts
127.0.0.1 localhost
172.31.4.70 ip-172-31-4-70
20.200.245.247 github.com

이후 git clone을 시도하여 레포지토리 클론에 성공했다!

root@ip-172-31-4-70:/home/ubuntu# git clone https://github.com/kosmo138/resumate
Cloning into 'resumate'...
remote: Enumerating objects: 3394, done.
remote: Counting objects: 100% (335/335), done.
remote: Compressing objects: 100% (210/210), done.
remote: Total 3394 (delta 156), reused 208 (delta 108), pack-reused 3059
Receiving objects: 100% (3394/3394), 22.46 MiB | 18.79 MiB/s, done.
Resolving deltas: 100% (1924/1924), done.
root@ip-172-31-4-70:/home/ubuntu# ls -l
total 4
drwxr-xr-x 9 root root 4096 Apr 12 22:36 resumate

FileZilla를 이용한 제외 파일 직접 전송

FileZilla 다운로드

실행한 후 상단 툴바의 가장 왼쪽 버튼을 클릭하여 새 연결을 다음과 같이 추가한다.

Image

이후 다음과 같이 원격지의 파일을 읽거나 쓸 수 있다.

Image

오류 2: permission denied

환경 변수 파일 전송을 시도하니 다음과 같은 오류가 표시되었다.

Command:    put "/Users/young/project/resumate/client/.env.local" ".env.local"
Error:          /home/ubuntu/resumate/client/.env.local: open for write: permission denied
Error:          File transfer failed

해당 디렉토리에서 Permission 또는 Ownership이 설정되지 않아 발생한 문제로 판단했다. Permission: resumate 디렉토리 내부의 파일의 권한은 모두 644로 설정되어 있어 문제는 없다 생각했다. Ownership: 다음의 명령을 수행했다.

ubuntu@ip-172-31-4-70:~$ sudo -s
root@ip-172-31-4-70:/home/ubuntu# chown -R ubuntu:ubuntu resumate

이후 파일 전송에 성공했다.

Status:         Starting upload of /Users/young/project/resumate/client/.env.local
Status:         File transfer successful, transferred 113 bytes in 1 second
Status:         Retrieving directory listing of "/home/ubuntu/resumate/client"...
Status:         Listing directory /home/ubuntu/resumate/client
Status:         Directory listing of "/home/ubuntu/resumate/client" successful

참고 문서: 🐧 리눅스 파일 & 디렉토리 권한 (소유권 / 허가권 / 특수권한)

suyons commented 3 months ago

Close #83