16.04 に Prometheus の最新バージョンをインストールするにはどうすればよいですか?

16.04 に Prometheus の最新バージョンをインストールするにはどうすればよいですか?

Ubuntu 16.04 の新規インストールに最新バージョンの Prometheus をインストールするのに問題があります。私が見つけたガイドはすべて 14.04 用であり、systemV から systemd に移行したため、16.04 でセットアップするときにこれらのガイドは互換性がありません (または少なくとも不完全です)。

Prometheus は apt からインストールできますが、バージョン 0.16.2 がインストールされ、現在のバージョンは 1.0.2 です。

私は公式のprometheus.io インストール ガイドそしてDigital Oceanのこのガイド

systemd のセットアップについて誰か手伝ってくれませんか? 私は Ubuntu については比較的経験がありますが、systemd の変更は私にとって予想外の出来事です。

答え1

プロメテウスをインストールするときに、次のユニットファイルが機能しましたサーババージョン 1.x (エクスポーターとは対照的)。

# /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=/usr/local/bin/prometheus-1.1.2.linux-amd64/prometheus \
                                -config.file=/etc/prometheus/prometheus.yml \
                                -storage.local.path=/var/lib/prometheus/data

[Install]
WantedBy=multi-user.target

もちろん、これは、prometheus ユーザーを作成し、必要な権限を付与していることを前提としています。

次に、WInfly で説明されているコマンドを使用します。

$ sudo systemctl daemon-reload
$ sudo systemctl enable prometheus
$ sudo systemctl start prometheus
$ sudo systemctl status prometheus

以下の内容が役に立ちました:

プロメテウス:https://blog.svedr.in/posts/prometheus-quick-start.html

ユニット ファイル ディレクティブのマニュアル ページ:https://www.freedesktop.org/software/systemd/man/systemd.directives.html

答え2

サーバー ストレージ引数名はバージョン 2.x で変更され、構文は次のようになりました。

[Unit]
Description=Prometheus Server
After=network-online.target

[Service]
User=root
Restart=on-failure
ExecStart=/usr/local/bin/prometheus-2.2.1.linux-amd64/prometheus \
                                --config.file=/etc/prometheus/prometheus.yml \
                                --storage.tsdb.path=/var/lib/prometheus/data

[Install]
WantedBy=multi-user.target

答え3

私は答えを見つけましたこの記事これを systemd で実行するように設定しようとしたときに欠けていた部分は、ユニット ファイルの作成でした。以下は、node_exporter のユニット ファイルを作成し、それをサービスとして実行する方法を示しています。これが他の誰かの役に立つことを願っています。

ユニットファイルを作成します。

$ sudo vim /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter

[Service]
User=vxx
ExecStart=/home/vxx/Prometheus/node_exporter/node_exporter

[Install]
WantedBy=default.target

次に、デーモンをリロードした後、サービスを開始するか、サーバーを再起動します。

$ sudo systemctl daemon-reload
$ sudo systemctl enable node_exporter.service
$ sudo systemctl start node_exporter.service
$ sudo systemctl status node_exporter.service

答え4

もしまだこの質問に戻ってくる人がいるなら、私はprometheus、node_exporter、apache_exporterのインストールをスクリプト化しました。このDigitalOceanチュートリアル

私のスクリプトはここにあります: https://github.com/icolwell/install_scripts

次のスクリプトが興味深いかもしれません:

prometheus_install.bash
prometheus_node_exporter_install.bash
prometheus_apache_exporter_install.bash

以下のコマンドを使用してスクリプトをダウンロードして実行できます。

wget https://raw.githubusercontent.com/icolwell/install_scripts/master/prometheus_install.bash
bash prometheus_install.bash

既存の Prometheus 構成はすべて上書きされることに注意してください。

関連情報