
이전 글 :
2025.02.20 - [모니터링] - [모니터링] Prometheus와 Grafana를 이용한 서버 모니터링 (1. 개념 정리)
이전 글에서는 Prometheus로 모니터링을 어떻게 수행하는지 기본 개념을 정리했다. 이번 글에서는 리눅스 서버에 Prometheus와 node-exporter, grafana를 설치하는 방법에 대해서 정리해보도록 하겠다.
1. Node-Exporter 설치
이전 글에서 설명했지만 Prometheus는 Exporter라고 하는 것을 통해 메트릭을 수집한다. Exporter는 개별적으로 메트릭 정보를 저장하거나 하진 않고, 일종의 인터페이스 역할을 한다고 보면 되겠다. 그 중 Node Exporter의 경우 OS 레벨의 리소스를 Prometheus가 수집할 수 있도록 하는 Exporter의 한 종류이다. 리눅스 서버에 설치할 때는 다음과 같은 순서로 설치가 가능하다.
1. 압축 파일 다운로드
https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
2. 압축 해제
tar -xzf node\_exporter-1.7.0.linux-amd64.tar.gz
3. 실행 파일 경로 변경 및 불필요한 파일 삭제
mv node\_exporter-1.7.0.linux-amd64/node\_exporter /usr/local/bin/
rm -rf node\_exporter-1.7.0.linux-amd64\*
4. systemd 서비스 파일 생성
cat <<EOF | tee /etc/systemd/system/node-exporter.service
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=root
ExecStart=/usr/local/bin/node_exporter # 실행 파일 경로
--web.listen-address=0.0.0.0:9100 # 프로메테우스 접근 포트
Restart=always
[Install]
WantedBy=multi-user.target EOF
5. 서비스 등록 및 실행
systemctl daemon-reload # systemd 데몬 리로드
systemctl start node-exporter # Node Exporter 서비스 시작
systemctl enable node-exporter # 부팅 시 자동 실행 설정
6. 완료 후 실행 상태 확인
systemctl status node-exporter

2. Prometheus 설치
이제 Exporter가 보내주는 메트릭을 수집할 주체인 Prometheus를 설치해보도록 하겠다.
1. 필요 디렉토리 생성
mkdir -p /etc/prometheus /var/lib/prometheus
2. Prometheus 바이너리 파일 다운로드
curl -LO https://github.com/prometheus/prometheus/releases/download/v2.51.2/prometheus-2.51.2.linux-amd64.tar.gz
3. 압축 해제
tar xvf prometheus-2.51.2.linux-amd64.tar.gz
4. 생성한 디렉토리로 파일 이동
mv prometheus-2.51.2.linux-amd64/prometheus /usr/local/bin/ # Prometheus 실행 파일
mv prometheus-2.51.2.linux-amd64/promtool /usr/local/bin/ # promtool : Prometheus 모니터링 툴
5. Prometheus 서비스 등록
tee /etc/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
ExecStart=/usr/local/bin/prometheus \\ # 실행 파일 경로
--config.file=/etc/prometheus/prometheus.yml \\ # 설정 파일 경로
--storage.tsdb.path=/var/lib/prometheus \\ # 스토리지 경로 (메트릭 수집 정보)
--web.listen-address="0.0.0.0:9090" # 이용자 or Grafana 포트
[Install] WantedBy=multi-user.target EOF
6. 서비스 시작
systemctl daemon-reload # 설정 내용 로드
systemctl enable prometheus # 부팅시 자동 시작 설정
systemctl start prometheus # 서비스 시작
7. 버전 확인으로 설치 확인
prometheus --version

여기까지는 설치 과정을 담았는데 설치만 했다고 모니터링을 수행할 수 있는 것은 아니다.. Exporter와 Prometheus간 연동 작업이 필수적으로 수행되어야하며, 가시적인 면에서 편리한 사용을 위해 Grafana의 설치 및 연동도 필요하다.. 다음 글을 통해 실제 Exporter와 Prometheus를 연동하는 방법 가이드를 살펴보도록 하겠다.
'모니터링' 카테고리의 다른 글
| [모니터링] Prometheus와 Grafana를 이용한 서버 모니터링 (3. node exporter, Prometheus 연동) (0) | 2025.10.13 |
|---|---|
| [모니터링] Prometheus와 Grafana를 이용한 서버 모니터링 (1. 개념 정리) (0) | 2025.02.20 |