두 개의 EC2 인스턴스에서 Prometheus + Node Exporter

발행: (2026년 2월 3일 오전 07:34 GMT+9)
8 분 소요
원문: Dev.to

I’m happy to translate the article for you, but I need the full text of the post (the paragraphs, headings, etc.) in order to do so. Could you please paste the content you’d like translated? I’ll keep the source line exactly as you provided and preserve all formatting, code blocks, URLs, and technical terms.

1️⃣ Architecture Overview (What we are building)

EC2 #1 — TARGET (Ubuntu)

  • Purpose: expose system metrics → 목적: 시스템 메트릭 노출
  • Tool: Node Exporter → 도구: Node Exporter
  • Port: 9100 → 포트: 9100

EC2 #2 — MONITOR (Ubuntu)

  • Purpose: collect and display metrics → 목적: 메트릭 수집 및 표시
  • Tool: Prometheus → 도구: Prometheus
  • Port: 9090 → 포트: 9090
Browser

Prometheus (Ubuntu, :9090)
   ↓ scrape
Node Exporter (Ubuntu, :9100)

2️⃣ AWS 보안 그룹 설정 (실험 모드)

⚠️ 프로덕션 환경에 적합하지 않음 – 교육 및 데모 용도로만 사용하세요.

2.1 보안 그룹 생성 (두 EC2 모두 동일한 단계)

AWS 콘솔 → EC2 → 보안 그룹 → 보안 그룹 생성

Inbound RulesProtocolPortSource
All trafficAllAll0.0.0.0/0

Outbound Rules – 기본값 유지: All traffic → 0.0.0.0/0

Attach this SG to:

  • 모니터 EC2
  • 타깃 EC2

3️⃣ TARGET EC2 (Ubuntu) – Node Exporter 설치

3.1 TARGET EC2에 연결

ssh ubuntu@<target-ip>

3.2 Node Exporter 다운로드

cd /tmp
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz

3.3 압축 해제 및 설치

tar -xvf node_exporter-1.7.0.linux-amd64.tar.gz
cd node_exporter-1.7.0.linux-amd64
sudo mv node_exporter /usr/local/bin/

3.4 Node Exporter 시작 (포그라운드 데모)

node_exporter

다음과 같은 출력이 표시됩니다:

Listening on :9100

3.5 Node Exporter 확인

ss -tulnp | grep 9100

메트릭 테스트:

curl http://localhost:9100/metrics | head

Node Exporter가 준비되었습니다

4️⃣ MONITOR EC2 (Ubuntu) – Prometheus 설치

4.1 MONITOR EC2에 연결

ssh ubuntu@<monitor-ip>

4.2 Prometheus 다운로드

cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v2.48.1/prometheus-2.48.1.linux-amd64.tar.gz

4.3 파일 추출

tar -xvf prometheus-2.48.1.linux-amd64.tar.gz
cd prometheus-2.48.1.linux-amd64

4.4 디렉터리 생성

sudo mkdir -p /etc/prometheus
sudo mkdir -p /var/lib/prometheus

4.5 바이너리 설치

sudo mv prometheus promtool /usr/local/bin/
prometheus --version

4.6 설정 파일 이동

sudo mv prometheus.yml /etc/prometheus/
sudo mv consoles console_libraries /etc/prometheus/

검증:

ls /etc/prometheus

예상 출력:

prometheus.yml
consoles
console_libraries

5️⃣ Prometheus 구성 (Ubuntu)

5.1 설정 편집

sudo nano /etc/prometheus/prometheus.yml

5.2 전체 파일을 다음 내용으로 교체

global:
  scrape_interval: 15s
  evaluation_interval: 15s

alerting:
  alertmanagers:
    - static_configs:
        - targets: []

rule_files: []

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]

  - job_name: "node"
    static_configs:
      - targets: [":9100"]

저장 (CTRL+O, Enter, CTRL+X).

5.3 설정 검증 (매우 중요)

promtool check config /etc/prometheus/prometheus.yml

예상 출력:

SUCCESS

6️⃣ Prometheus 시작 (Ubuntu)

prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/var/lib/prometheus

다음과 같은 메시지를 찾으세요:

Server is ready to receive web requests.

7️⃣ Prometheus UI 접근

브라우저를 열고 다음 주소로 이동합니다:

http://<monitor-ip>:9090

그런 다음 Status → Targets 로 이동합니다.

✅ 기대 결과

prometheus   UP
node         UP

다음이 확인됩니다:

  • 네트워킹 작동
  • 보안 그룹 작동
  • 메트릭이 수집되고 있음

8️⃣ 실시간 데모 쿼리 (Ubuntu Lab)

Graph 탭으로 이동합니다.

8.1 대상 확인

up

8.2 CPU 사용량 (%)

100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)

8.3 메모리 사용량 (%)

(node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) 
/ node_memory_MemTotal_bytes * 100

8.4 디스크 사용량 (%)

100 * (1 - (node_filesystem_avail_bytes{mountpoint="/"} 
/ node_filesystem_size_bytes{mountpoint="/"}))

Node Exporter는 이제 Prometheus가 수집하고 시각화할 수 있는 시스템 메트릭을 노출합니다.

📦 Overview

  • Node ExporterTARGET EC2에서 실행되며 포트 9100에서 메트릭을 노출합니다.
  • Prometheus는 정해진 간격으로 해당 메트릭을 수집합니다.
  • 대상이 UP 상태이면 모니터링이 정상적으로 동작합니다.
  • Security Groups는 네트워크 접근을 제어합니다 – Linux 수준의 방화벽이 아닙니다.

10️⃣ 우리가 의도적으로 허용한 것 (Lab Mode)

구성 요소허용
SG 인바운드전체 트래픽
IPv40.0.0.0/0
포트9090, 9100
✅ 쉬운 학습❌ 프로덕션에 안전하지 않음

📊 Grafana 배치 및 설정 (Ubuntu, AWS EC2)

🔹 Grafana는 어디에 배치하나요?

Grafana는 MONITOR EC2에 설치됩니다, Prometheus와 함께.

최종 아키텍처 (매우 중요)

TARGET EC2 (Ubuntu)
└── Node Exporter
    └── :9100 (/metrics)

MONITOR EC2 (Ubuntu)
├── Prometheus
│   └── :9090 (scrapes node exporter)
└── Grafana
    └── :3000 (visualizes Prometheus data)

왜 Grafana를 MONITOR EC2에 두는가

  • Grafana는 메트릭을 수집하지 않습니다 – 시각화만 합니다.
  • Prometheus가 데이터 소스입니다.
  • Grafana를 Prometheus와 같은 위치에 두면 다음과 같은 장점이 있습니다:
    • 네트워크 구성이 간단해짐
    • 실제 운영 환경 패턴
    • 교육이 쉬워짐
✅ 올바른❌ 잘못된
Prometheus + Grafana가 같은 EC2에 있음Grafana가 대상 노드에 있음

🧩 단계별: Ubuntu에 Grafana 설치 (MONITOR EC2)

단계명령어 / 작업
1️⃣ MONITOR EC2에 연결ssh ubuntu@<monitor-ip>
2️⃣ 시스템 업데이트sudo apt update
3️⃣ 필수 패키지 설치sudo apt install -y apt-transport-https software-properties-common wget
4️⃣ Grafana GPG 키 추가wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
예상 출력: OK
5️⃣ Grafana 저장소 추가echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
6️⃣ Grafana 설치sudo apt update
sudo apt install -y grafana
7️⃣ Grafana 시작 및 활성화sudo systemctl start grafana-server
sudo systemctl enable grafana-server
상태 확인sudo systemctl status grafana-server
예상: Active: active (running)
8️⃣ 보안 그룹에서 Grafana 포트 열기 (실험 모드)MONITOR EC2에 대한 인바운드 규칙이 모든 트래픽을 허용하거나 최소한 포트 3000을 허용하도록 설정합니다.
9️⃣ Grafana UI 접근브라우저를 열고 http://<monitor-ip>:3000 로 이동합니다.
기본 로그인Username: admin
Password: admin (로그인 후 비밀번호 변경을 요청받게 됩니다)
🔗 Grafana를 Prometheus에 연결1. Settings → Data Sources → Add data source → Prometheus.
2. Name: Prometheus.
3. URL: http://localhost:9090.
4. Save & Test 클릭.
예상: Data source is working.
📈 Node Exporter 대시보드 가져오기1. + (Create)Import.
2. Dashboard ID 1860Load.
3. Prometheus 데이터 소스 선택 → Import.
CPU, 메모리, 디스크, 네트워크, 로드 평균 그래프가 표시됩니다.

🧠 일반적인 문제 및 해결 방법

증상확인 / 해결
Grafana 페이지가 열리지 않음- EC2 보안 그룹에서 포트 3000이 허용되어 있는지 확인하세요.
- 서비스가 실행 중인지 확인하세요: sudo systemctl status grafana-server.
Grafana에 데이터가 없음- Prometheus 데이터 소스 URL이 정확히 http://localhost:9090인지 확인하세요.
- Grafana에서 데이터 소스를 테스트하세요 (Save & Test).
대시보드가 비어 있음- Prometheus 타깃이 UP 상태여야 합니다.
- 메트릭이 수집되고 표시될 때까지 1~2분 정도 기다리세요.

모니터링을 즐기세요! 🎉

Back to Blog

관련 글

더 보기 »