구성 요소 개요
Linux 시스템 모니터링을 위해 Prometheus, Grafana, Node Exporter를 조합하여 사용합니다. 각 요소의 역할은 다음과 같습니다:
- Prometheus: 시계열 데이터 기반의 오픈소스 모니터링 시스템으로 데이터 저장 및 알림 기능 제공
- Grafana: 다중 데이터 소스를 지원하는 시각화 플랫폼으로 메트릭 분석 및 대시보드 구현
- Node Exporter: 시스템 자원 사용량 수집기로 CPU, 메모리, 디스크 등의 데이터 수집
CentOS 7 환경 설치
Prometheus 설치
# Prometheus 설치
wget https://github.com/prometheus/prometheus/releases/download/v2.28.1/prometheus-2.28.1.linux-amd64.tar.gz
tar xvf prometheus-*.tar.gz
mv prometheus-*/prometheus /usr/local/bin/
# 설정 파일 준비
mkdir /etc/prometheus
mv prometheus-*/prometheus.yml /etc/prometheus/
# 서비스 설정
cat > /etc/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus Monitoring
After=network.target
[Service]
ExecStart=/usr/local/bin/prometheus \\
--config.file=/etc/prometheus/prometheus.yml \\
--storage.tsdb.path=/var/lib/prometheus
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# 서비스 시작
systemctl daemon-reload
systemctl enable --now prometheus
Grafana 설치
# Grafana 설치
wget https://dl.grafana.com/oss/release/grafana-8.3.3-1.x86_64.rpm
yum install -y grafana-*.rpm
# 서비스 활성화
systemctl enable --now grafana-server
Node Exporter 설치
# Node Exporter 설치
wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
tar xvf node_exporter-*.tar.gz
mv node_exporter-*/node_exporter /usr/local/bin/
# 서비스 설정
cat > /etc/systemd/system/node_exporter.service <<EOF
[Unit]
Description=Node Exporter
After=network.target
[Service]
ExecStart=/usr/local/bin/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
# 서비스 시작
systemctl daemon-reload
systemctl enable --now node_exporter
# Prometheus 설정에 타겟 추가
echo >> /etc/prometheus/prometheus.yml <<EOF
- job_name: 'system_metrics'
static_configs:
- targets: ['localhost:9100']
EOF
systemctl restart prometheus
웹 인터페이스 설정
Prometheus 접속: http://서버IP:9090
타겟 상태 확인: Status → Targets
Grafana 설정: http://서버IP:3000 (기본 계정: admin/admin)
데이터 소스 연동
- Configuration → Data Sources 선택
- Prometheus 선택 후 URL 설정: http://localhost:9090
- Save & Test 클릭하여 연결 확인
대시보드 생성
- Create → Import 선택
- Grafana 대시보드 ID 입력: 1860 (Node Exporter Full)
- 데이터 소스로 Prometheus 선택
최종 결과 예시: