kosmo138 / resumate

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

전체 앱 1차 배포 #88

Closed suyons closed 3 months ago

suyons commented 3 months ago

문제 1

apt update를 시도하니 다음과 같이 호스트에 연결할 수 없다는 오류가 표시되었다.

root@ip-172-31-4-70:/home/ubuntu/resumate# apt update
Ign:1 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy InRelease
Ign:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:3 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease
Ign:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:4 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease
Ign:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
Ign:1 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy InRelease
Err:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
  Temporary failure resolving 'security.ubuntu.com'

해결 1

ping 테스트를 진행한 결과 도메인 네임을 해석할 수 없다는 응답을 확인했다.

root@ip-172-31-4-70:/home/ubuntu/resumate# ping ap-northeast-2.ec2.archive.ubuntu.com
ping: ap-northeast-2.ec2.archive.ubuntu.com: Temporary failure in name resolution

하지만 로컬 PC에서는 ping 테스트 결과가 정상이었다.

C:\Users\kosmo>ping ap-northeast-2.ec2.archive.ubuntu.com

Pinging ap-northeast-2.ec2.archive.ubuntu.com [52.79.128.16] with 32 bytes of data:
Reply from 52.79.128.16: bytes=32 time=3ms TTL=42
Reply from 52.79.128.16: bytes=32 time=3ms TTL=42
Reply from 52.79.128.16: bytes=32 time=3ms TTL=42
Reply from 52.79.128.16: bytes=32 time=3ms TTL=42

Ping statistics for 52.79.128.16:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 3ms, Maximum = 3ms, Average = 3ms

이슈 #83 때와 같이 이번에도 호스트를 IP 주소로 해석할 수 없는 것이 문제라고 판단했다.

먼저 호스트 파일에 도메인 네임과 IP주소 매핑을 추가했다.

vim /etc/hosts
127.0.0.1 localhost
172.31.4.70 ip-172-31-4-70
20.200.245.247 github.com
52.79.128.16 ap-northeast-2.ec2.archive.ubuntu.com
185.125.190.39 security.ubuntu.com

ping 테스트는 성공했다.

root@ip-172-31-4-70:/# ping ap-northeast-2.ec2.archive.ubuntu.com
PING ap-northeast-2.ec2.archive.ubuntu.com (52.79.128.16) 56(84) bytes of data.
64 bytes from ap-northeast-2.ec2.archive.ubuntu.com (52.79.128.16): icmp_seq=1 ttl=63 time=0.405 ms
64 bytes from ap-northeast-2.ec2.archive.ubuntu.com (52.79.128.16): icmp_seq=2 ttl=63 time=0.448 ms
64 bytes from ap-northeast-2.ec2.archive.ubuntu.com (52.79.128.16): icmp_seq=3 ttl=63 time=0.404 ms
64 bytes from ap-northeast-2.ec2.archive.ubuntu.com (52.79.128.16): icmp_seq=4 ttl=63 time=0.411 ms

--- ap-northeast-2.ec2.archive.ubuntu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3018ms
rtt min/avg/max/mdev = 0.404/0.417/0.448/0.018 ms

apt update까지 성공했다.

root@ip-172-31-4-70:/# apt update
Hit:1 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy InRelease
Hit:2 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:3 http://ap-northeast-2.ec2.archive.ubuntu.com/ubuntu jammy-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
35 packages can be upgraded. Run 'apt list --upgradable' to see them.

문제 2

이후 ping 테스트는 성공했고, 더 근본적인 원인을 추정해 보았다.

DNS 서버의 주소가 추가되어 있지 않은 것이 문제일 것이다.

해결 2

다음의 글에 따라 Google 운영 DNS 서버의 IP주소를 추가했다.

https://vegastack.com/tutorials/how-to-set-dns-nameservers-on-ubuntu-22-04/

root@ip-172-31-4-70:/# vim /etc/resolv.conf
nameserver 127.0.0.53
nameserver 8.8.8.8
nameserver 8.8.4.4
options edns0 trust-ad
search ap-northeast-2.compute.internal
root@ip-172-31-4-70:/# resolvectl status
Global
       Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: stub

Link 2 (eth0)
Current Scopes: DNS
    Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
    DNS Servers: 8.8.8.8 8.8.4.4 172.31.0.2
    DNS Domain: ap-northeast-2.compute.internal

이후 host 파일에 없는 도메인 이름으로의 ping 테스트에도 성공했다.

root@ip-172-31-4-70:/# ping www.google.com
PING www.google.com (142.250.206.228) 56(84) bytes of data.
64 bytes from kix06s10-in-f4.1e100.net (142.250.206.228): icmp_seq=1 ttl=46 time=33.4 ms
64 bytes from kix06s10-in-f4.1e100.net (142.250.206.228): icmp_seq=2 ttl=46 time=33.3 ms
64 bytes from kix06s10-in-f4.1e100.net (142.250.206.228): icmp_seq=3 ttl=46 time=33.3 ms
64 bytes from kix06s10-in-f4.1e100.net (142.250.206.228): icmp_seq=4 ttl=46 time=33.3 ms

--- www.google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 20290ms
rtt min/avg/max/mdev = 33.288/33.313/33.369/0.029 ms

문제 3

Docker를 설치해야 한다.

해결 3

다음의 공식 문서를 따라 쉽게 설치했다.

https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
root@ip-172-31-4-70:/# docker --version
Docker version 26.0.1, build d260a54

문제 4

Docker에서 Image를 Pull 할 수 없었다.

root@ip-172-31-4-70:/home/ubuntu/resumate# docker compose up
WARN[0000] /home/ubuntu/resumate/docker-compose.yml: `version` is obsolete
[+] Running 4/4
 ✘ server Error context canceled                                                                                  35.0s
 ✘ data Error   context canceled                                                                                  35.0s
 ✘ client Error Get "https://registry-1.docker.io/v2/": context deadline exceeded      35.0s
 ✘ nginx Error  context canceled                                                                                  35.0s
 Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded

hello-world조차 안 되었다.

# docker pull hello-world
Using default tag: latest
Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
root@ip-172-31-4-70:/home/ubuntu/resumate# usermod -aG docker ubuntu
root@ip-172-31-4-70:/home/ubuntu/resumate# docker pull hello-world
Using default tag: latest
Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

해결 4

현재 사용자인 root가 docker 그룹에 포함되지 않은 것이 문제라 생각했다.

아래의 글을 참고하여 추가했다.

https://www.baeldung.com/linux/docker-permission-denied-daemon-socket-error

usermod -aG docker root
systemctl restart docker.service

그러나 동일 오류가 지속되었다

curl을 이용하여 해당 주소로 요청을 날려 보았다. 이번에 또 다시 호스트를 찾을 수 없다고 한다.

root@ip-172-31-4-70:/home/ubuntu/resumate# curl -X GET "https://registry-1.docker.io/v2/"
curl: (6) Could not resolve host: registry-1.docker.io

원인을 찾았다, /etc/resolv.conf에 추가한 nameserver 들이 지워진 것이었다. 다시 추가한 이후로는 GET 요청에 대해 JSON을 응답했다.

# curl -X GET "https://registry-1.docker.io/v2/"
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":null}]}

이후 hello-world 이미지 실행에 성공했다.

root@ip-172-31-4-70:/home/ubuntu/resumate# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:03b30c6a3c320ff172b52bd68eddffde6ded08ce47e650fe52de861c5e9df46d
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
root@ip-172-31-4-70:/home/ubuntu/resumate# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

문제 5

/etc/resolv.conf 파일에 추가한 nameserver 8.8.8.8이 계속 초기화된다.

해결 5

/etc/resolv.conf 파일은 systemd-resolved 서비스에 의해 관리되는 파일이다.

참고: https://velog.io/@markyang92/systemd-managing-network

# vim /etc/systemd/resolved.conf
[Resolve]
DNS=8.8.8.8
FallbackDNS=8.8.4.4

systemd-resolved의 설정 파일인 resolved.conf에 DNS 주소를 추가했음에도 /etc/resolv.conf에 적용되지 않았다.

# systemctl restart systemd-resolved
# nslookup www.google.com
;; communications error to 127.0.0.53#53: timed out

resolv.conf를 심볼릭 링크로 새로 만들기로 했다.

백업 먼저 하고 진행했다.

# cp /etc/resolv.conf /etc/resolv.conf.bak
# ls -l | grep .bak
-rw-r--r-- 1 root root        950 Apr 15 16:45 resolv.conf.bak
# rm -rf /etc/resolv.conf
# ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
# ls -l /etc | grep resolv.conf
lrwxrwxrwx 1 root root         36 Apr 15 16:48 resolv.conf -> /run/systemd/resolve/stub-resolv.conf
-rw-r--r-- 1 root root        950 Apr 15 16:45 resolv.conf.bak

드디어 resolv.conf 파일에 nameserver가 추가되었다.

# vim /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.8.8
nameserver 8.8.4.4
# Too many DNS servers configured, the following entries may be ignored.
nameserver 172.31.0.2
search ap-northeast-2.compute.internal

www.google.com 도메인 네임 해석도 잘 되었다.

# nslookup www.google.com
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
Name:   www.google.com
Address: 142.250.206.228
Name:   www.google.com
Address: 2404:6800:400a:80a::2004

문제 6

EC2 프리티어 인스턴스(t2.micro)의 자원 부족으로 인해 Docker 컨테이너를 실행할 수 없음

해결 6

기존의 Docker 기반 실행 환경을 모두 로컬 실행으로 전환해야 했다.

또한, Next.js와 Spring Boot 프로젝트를 EC2에서 빌드하는 것조차 자원이 너무 많이 소모되어

로컬 개발 환경에서 빌드를 하고 SFTP를 이용하여 빌드 파일을 전송하여 실행했다.

image

suyons commented 3 months ago

Close #88