LoginSignup
18
14

More than 5 years have passed since last update.

CentOS7にPrometheusをInstall

Last updated at Posted at 2018-07-30

ネットワーク・サーバー監視ツールの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ポートでlistenするので開放します

# 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に接続すると
以下のようなページが表示されると思います。
スクリーンショット 2018-07-30 12.49.22.png

参考

インフラ・サービス監視ツールの新顔「Prometheus」入門
CentOS 7 に Prometheus 入れる

18
14
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
14