CentOS7에 Prometheus를 Install

네트워크 서버 모니터링 도구 Prometheus를 설치했으므로,
거기까지의 비망록입니다.

환경



CentOS Linux release 7.5
Prometheus 2.3.2
Node exporter 0.16.0

이번에는 프로메테우스 서버를 192.168.0.1, 감시 대상 서버를 192.168.0.2로 진행하고 싶습니다. IP 주소는 각 환경에 맞춰야 합니다.

node_exporter 설치



port 개방



디폴트라면 9100포트에서 listen하므로 개방합니다
# firewall-cmd --add-port=9100/tcp --zone=public --permanent
# firewall-cmd --reload
-- 確認 --
# firewall-cmd --list-ports --zone=public
9100/tcp

Node Exporter 설치


# mkdir /usr/local/src/prometheus
# cd /usr/local/src/prometheus
# wget https://github.com/prometheus/node_exporter/releases/download/v0.16.0/node_exporter-0.16.0.linux-amd64.tar.gz
# tar zxvf node_exporter-0.16.0.linux-amd64.tar.gz
# mv node_exporter-0.16.0.linux-amd64 node_exporter

시작 스크립트 작성


[Unit]
Description=Node Exporter
Documentation=https://github.com/prometheus/node_exporter

[Service]
Type=simple
ExecStart=EnvironmentFile=/usr/local/src/prometheus/node_exporter/node_exporter $OPTIONS
Restart=always

[Install]
WantedBy=multi-user.target

시작



/usr/lib/systemd/system/prometheus-node-exporter.service
# systemctl daemon-reload
-- 自動起動設定 --
# systemctl enable prometheus.service
-- 起動 --
# systemctl start prometheus.service

확인



http://<감시 대상 서버의 IP 주소>/metrics에 연결하면
아래와 같은 상태가 기재된 페이지가 열린다고 생각합니다.
# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 4.4412e-05
go_gc_duration_seconds{quantile="0.25"} 6.5151e-05
go_gc_duration_seconds{quantile="0.5"} 7.8829e-05
go_gc_duration_seconds{quantile="0.75"} 0.000107801
go_gc_duration_seconds{quantile="1"} 0.004286416
go_gc_duration_seconds_sum 0.013319998
go_gc_duration_seconds_count 97
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 9
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
(略)

Prometheus Server 배포



port 개방



프로메테우스 서버는 디폴트이면 9090포트에서 청취하므로 개방합니다
# firewall-cmd --add-port=9090/tcp --zone=public --permanent
# firewall-cmd --reload
# firewall-cmd --list-ports --zone=public

Prometheus Server 설치


# mkdir /usr/local/src/prometheus
# cd /usr/local/src/prometheus
# wget https://github.com/prometheus/prometheus/releases/download/v2.3.2/prometheus-2.3.2.linux-amd64.tar.gz
# tar zxvf prometheus-2.3.2.linux-amd64.tar.gz
# mv prometheus-2.3.2.linux-amd64 promethus-server
# cd promethus-server
# cp prometheus.yml prometheus.yml.org

/usr/local/src/prometheus/prometheus-server/prometheus.yml
# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets:
        - '192.168.0.2:9100'

시작 스크립트 작성



/usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus - Monitoring system and time series database
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/local/src/prometheus/prometheus-server/prometheus \
  --config.file=/usr/local/src/prometheus/prometheus-server/prometheus.yml \

[Install]
WantedBy=multi-user.target

시작


# systemctl daemon-reload
自動起動設定
# systemctl enable prometheus.service
起動
# systemctl start prometheus.service

확인



http://<프로메테우스 서버의 IP 주소>:9090/graph에 접속하면
아래와 같은 페이지가 표시된다고 생각합니다.


참고



인프라 서비스 감시 도구의 새로운 얼굴 "Prometheus"입문
CentOS 7에 Prometheus 넣기

좋은 웹페이지 즐겨찾기