とりあえず構築 CentOS7 de Prometheus v2.28.1


はじめに

ほぼ趣味で監視のOSSは色々と触りましたが最近はprometheusばかり触っています。
最初のハードルは高めですが慣れれば良い感じです。

そんなprometheusをとりあえず動かしてみるか。そんな人向けにとりあえず構築メモ。

Prometheusは複数のOSSを組み合わせて動かすので必要に応じて次のソフトウェアも必要です。
このメモはprometheus単体のとりあえずインストールする内容です。

・Promehetus ※監視
  インストール:とりあえず構築 CentOS7 de Prometheus v2.28.1
・Cortex or Thanos ※監視データ長期保存@勉強中
・Grafana ※可視化
  インストール:とりあえず構築 CentOS7 de Grafana(+nginx proxy)
・alertmanager ※通知
・exporter
- node_exporter ※エージェント監視(パフォーマンス)
- snmp_exporter ※SNMP監視
- blackbox_exporter ※死活監視(ICMP・DNS・http)
- vmware_exporter ※vSphere監視
(上記をよく使う。他は必要に応じて勉強中)

前提

・Intel CPU 64bit
・CentOS 7.9
・Prometheus v2.28.1

OS 設定

・UTF-8を設定
localectl set-locale LANG=en_US.UTF-8

・設定ファイルの配置ディレクトリ作成
mkdir -p /opt/prometheus/etc/

・ソースの配置ディレクトリ作成
mkdir -p /opt/prometheus/src/

・監視データ保存場所のディレクトリ作成
mkdir -p /opt/prometheus/data

Prometheusインストール

cd /opt/prometheus/src/
curl -O -L https://github.com/prometheus/prometheus/releases/download/v2.28.1/prometheus-2.28.1.linux-amd64.tar.gz
tar xvzf prometheus-2.28.1.linux-amd64.tar.gz
mv prometheus-2.28.1.linux-amd64 prometheus-server
sudo chown -R root:root prometheus-server

cp -p /opt/prometheus/src/prometheus-server/prometheus.yml /opt/prometheus/etc/prometheus.yml
ln -s /opt/prometheus/src/prometheus-server/promtool /usr/bin/promtool

vi /etc/systemd/system/prometheus-server.service

/etc/systemd/system/prometheus-server.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
User=root
Restart=always
ExecStart=/opt/prometheus/src/prometheus-server/prometheus --config.file=/opt/prometheus/etc/prometheus.yml --web.enable-lifecycle --web.enable-admin-api --storage.tsdb.path=/opt/prometheus/data/ --storage.tsdb.retention=365d
[Install]
WantedBy=multi-user.target
  • --storage.tsdb.retention=365d でとりあえず1年保存設定になっています。
  • --storage.tsdb.path=/opt/prometheus/data/ で監視データの保存場所を指定しています。
  • --web.enable-admin-api で管理用http apiを有効にしています。
  • --web.enable-lifecycle でhttpでprometheusのリスタートをできるようにしています。

systemctl daemon-reload
systemctl start prometheus-server
systemctl status prometheus-server
systemctl enable prometheus-server

インストール確認

ブラウザで http://[ip address]:9090/ にアクセスできればOKです。