티스토리 뷰

개요

  • Prometheus는 기본적으로 원격 연결이 가능한 시계열 데이터베이스이다. Prometheus의 진정한 강점은 원격지에 위치한 다수의 서버에 대해 모니터링 관련 시계열 데이터를 수집하여 적재하고, 시각화 기능을 제공하는데 있다. 탄생 배경과 쓰임새 모두 서버 인스턴스 모니터링에 최적화되어 있다. 일반적으로 단독 사용보다는 대시보드 시각화 기능이 우수한 Grafana에 원격 데이터 소스를 제공하는 역할로 주로 사용된다. 이번 글에서는 CentOS 7PrometheusNode Exporter를 설치하고 설정하는 방법을 소개하고자 한다.

방화벽 개방

  • PrometheusTCP 9090 포트로 서비스되므로 외부(Grafana 서버)에서 데이터 소스로 연결시 방화벽 개방이 필요하다.
  • Node ExporterTCP 9100 포트로 서비스되므로 외부(Prometheus 중앙 서버)에서 시계열 데이터 수집시 방화벽 개방이 필요하다.

Prometheus 설치

  • 아래는 CentOS 7에서 각 인스턴스에 Prometheus를 설치하는 방법이다.
# Prometheus 설치
$ sudo useradd -m -s /bin/bash prometheus
$ su - prometheus
$ wget https://github.com/prometheus/prometheus/releases/download/v2.21.0/prometheus-2.21.0.linux-amd64.tar.gz
$ tar -xzvf prometheus-2.21.0.linux-amd64.tar.gz
$ mv prometheus-2.21.0.linux-amd64/ prometheus
$ exit

# Prometheus 서비스 작성
$ sudo nano /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target

[Service]
User=prometheus
Restart=on-failure
ExecStart=/home/prometheus/prometheus/prometheus \
  --config.file=/home/prometheus/prometheus/prometheus.yml \
  --storage.tsdb.path=/home/prometheus/prometheus/data

[Install]
WantedBy=multi-user.target

# Prometheus 서비스 시작
$ sudo systemctl daemon-reload
$ sudo systemctl start prometheus
$ sudo systemctl status prometheus

# 재부팅시 Prometheus 서비스 자동 실행 설정
$ sudo systemctl enable prometheus

# Prometheus 접속 확인
$ curl -X GET http://localhost:9090
<a href="/graph">Found</a>.

Node Exporter 설치

  • Node Exporter는 웹 서비스로 작동하며, 현재 자신의 모니터링 지표를 http://localhost:9100/metrics 엔드포인트로 제공하는 기능을 한다. 원격지에 위치한 Prometheus 중앙 서버에서는 각 인스턴스의 엔드포인트를 특정 주기 단위로 호출하여 시계열 데이터를 수집할 수 있고, 궁극적으로 Grafana에서 대시보드로 Prometheus 데이터 소스에 연결하여 각 인스턴스의 현황을 모니터링할 수 있다.
  • 아래는 CentOS 7에서 각 인스턴스에 Node Exporter를 설치하는 방법이다.
# Node Exporter 설치
$ su - prometheus
$ wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
$ tar -xzvf node_exporter-1.0.1.linux-amd64.tar.gz
$ mv node_exporter-1.0.1.linux-amd64/ node_exporter
$ exit

# Node Exporter 서비스 작성
$ sudo nano /etc/systemd/system/node_exporter.service
[Unit]
Description=Prometheus Node Exporter
Documentation=https://prometheus.io/docs/guides/node-exporter/
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Restart=on-failure
ExecStart=/home/prometheus/node_exporter/node_exporter

[Install]
WantedBy=multi-user.target

# Node Exporter 서비스 시작
$ sudo systemctl daemon-reload
$ sudo systemctl start node_exporter
$ sudo systemctl status node_exporter

# 재부팅시 Node Exporter 서비스 자동 실행 설정
$ sudo systemctl enable node_exporter

# Node Exporter 접속 확인
$ curl -X GET http://localhost:9100/metrics
  • 이제 원격지에 위치한 Prometheus 중앙 서버에 앞서 각 인스턴스에 설치한 Node Exporter를 연동할 차례이다.
# Prometheus 설정 추가
$ su - prometheus
$ nano /home/prometheus/prometheus/prometheus.yml
scrape_configs:
  - job_name: 'some-node-1'
    static_configs:
    - targets: ['localhost:9100']

# Prometheus 서비스 재시작
$ sudo systemctl restart prometheus
$ sudo systemctl status prometheus
  • job_name에는 시계열 데이터를 수집할 인스턴스의 이름을 적절하게 지정하면 된다. Grafana에서 선택 가능한 Job으로 노출되므로 식별하기 좋은 이름을 지정하면 된다.
  • targets에는 각 인스턴스의 원격지 주소를 입력하면 된다.

참고 글

댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함