LoginSignup
1
1

More than 3 years have passed since last update.

CentOS8にPrometheusをインストールする

Last updated at Posted at 2020-02-02

はじめに

Prometheusを触ってみたかったので動かしてみます。
Prometheusは複数のコンポーネントで構成され、今回説明するのは Prometheus 本体です。
それ以外にも「exporter(監視エージェント)」や「alertmanager(通知の実行)」などが存在します。

環境

インストールの前提となる環境は以下のとおりです。

  • OS:CentOS8
  • selinux:無効
  • firewalld:無効
  • Prometheusはバイナリを使用(Dockerは使用しない)
  • インストールディレクトリ: /usr/prometheus
  • Prometheusバージョン:2.15.2

インストール

それではインストールを行います。
作業に必要なパッケージとPrometheusインストールします。

yum install -y  wget  tar
mkdir /usr/prometheus

cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v2.15.2/prometheus-2.15.2.linux-amd64.tar.gz
tar zxvf prometheus-2.15.2.linux-amd64.tar.gz

mv ./prometheus-2.15.2.linux-amd64/* /usr/prometheus/
rm prometheus-2.15.2.linux-amd64.tar.gz
rmdir prometheus-2.15.2.linux-amd64
cd /usr/prometheus
chown root:root -R /usr/prometheus

※ /tmp は作業用のディレクトリです

systemd ユニットファイルの作成

ダウンロードしたバイナリを実行すれば起動しますが、ユニットファイルを作成していきましょう。

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

[Install]
WantedBy=multi-user.target

[Service]
Type=simple
ExecStart=/usr/prometheus/prometheus \
--config.file=/usr/prometheus/prometheus.yml
ExecReload=/bin/kill -HUP $MAINPID
Restart=no

作成したユニットファイルを読み込み、Prometheusを起動します。

systemctl daemon-reload
systemctl enable prometheus
systemctl start prometheus

起動確認

ブラウザで http://<IPアドレス>:9090/ にアクセスできるか確認しましょう。

気になるオプション

細かい動作の検証ができていませんがこのあたりのオプションを変更する事がありそうです。
ユニットファイルのExecStartの項目に付け足していきます。

オプション 内容
--web.listen-address=localhost:9090 localhostからのみに変更 1
--storage.tsdb.retention.time データ保持期間
--storage.tsdb.retention.size データ保存サイズ
--storage.tsdb.wal-compression WALを圧縮
--storage.tsdb.path データ保存するパスを指定(デフォルトのままだと /data/ に保存される)

必要に応じて /usr/lib/systemd/system/prometheus.service を書き換えます。
※/usr/lib/systemd/system/prometheus.service を修正した場合は 「systemctl daemon-reload && systemctl restart prometheus」を都度実行しましょう。
参考:「RedHat」SYSTEMD のユニットファイルの作成および変更

それ以外のオプションはヘルプで確認できます。

/usr/prometheus/prometheus --help

コンフィグの場所がわかりにくい

/etc/ 配下をとりあえず探してしまう方のためにひと工夫しておきましょう。

コンフィグファイル自体は /usr/prometheus にあるのでシンボリックリンクを設定します。
(コンフィグファイル自体を動かして ExecStartの「--config.file」を修正しても良いでしょう)

ln -s /usr/prometheus/prometheus.yml /etc/prometheus.yml

終わりに

本体をインストールしただけなので、まだ監視ができていません。
次はexporterを動かして監視する記事がかけたら良いですね。

更新履歴

2020/03/08
気になるオプションにstorage.tsdb.pathを追加しました。


  1. アカウントやIPアドレスによるアクセス制限ができないので、Apacheなどをかませて使用すると良さそう 

1
1
0

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
1
1