GNU/Linux >> Linux の 問題 >  >> Debian

Debian11にPrometheusシステム監視ツールをインストールする方法

Prometheusは、サービスからメトリックを収集し、それらを時系列データベースに保存する、無料のオープンソースのWebベースの監視アプリケーションです。 Prometheusのデフォルト構成は、それ自体に関するメトリックのみをエクスポートします。ただし、エクスポーターやその他のプログラムをインストールすることで拡張できます。多次元データモデル、グラフ化とダッシュボードの複数のモードをサポートします。

この投稿では、Debian11にPrometheusモニタリングをインストールする方法を紹介します。

前提条件
  • Debian11を実行しているサーバー。
  • ルートパスワードはサーバーで構成されています。
プロメテウスをインストール

開始する前に、Prometheus専用のユーザーとグループを作成することをお勧めします。次のコマンドを使用して作成できます:

 groupadd --system prometheus 
useradd -s / sbin / nologin --system -g prometheus prometheus

次に、次のコマンドを実行して、最新バージョンのPrometheusをダウンロードします。

 curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d'"' -f 4 | wget -qi-

Prometheusがダウンロードされると、次のコマンドを使用してダウンロードされたファイルを表示できます。

 ls -l <​​/ pre> 

次の出力が表示されます。

-rw-r--r--1ルートルート7263807810月5日16:46prometheus-2.30.3.linux-amd64.tar.gz

次に、次のコマンドを使用して、ダウンロードしたファイルを抽出します。

 tar -xvf prometheus * .tar.gz 

次に、次のコマンドを使用して、ディレクトリを抽出したディレクトリに変更します。

 cd prometheus-2.30.3.linux-amd64 

次に、次のコマンドを使用して、必要なディレクトリをいくつか作成します。

 mkdir / etc / prometheus 
mkdir / var / lib / prometheus

次に、次のコマンドを使用して、必要な構成ファイルとツールをコピーします。

 mv prometheus.yml /etc/prometheus/prometheus.yml 
mv consoles / console_libraries / / etc / prometheus /
mv prometheus promtool / usr / local / bin /

完了したら、次のステップに進むことができます。

PrometheusのSystemdサービスファイルを作成する

次に、Prometheusサービスを管理するためのsystemdサービスファイルを作成する必要があります。次のコマンドを実行して作成できます:

 nano /etc/systemd/system/prometheus.service 

次の行を追加します:

 [Unit] Description =PrometheusDocumentation =https://prometheus.io/docs/introduction/overview/Wants=network-online.targetAfter=network-online.target [Service] Type =simpleUser =prometheusGroup =prometheusExecReload =/ bin / kill -HUP $ MAINPIDExecStart =/ usr / local / bin / prometheus \ --config.file =/ etc / prometheus / prometheus.yml \ --storage.tsdb.path =/ var / lib / prometheus\--web。 console.templates =/ etc / prometheus / consoles \ --web.console.libraries =/ etc / prometheus / console_libraries \ --web.listen-address =0.0.0.0:9090 \ --web.external-url =SyslogIdentifier =prometheusRestart =always [Install] WantedBy =multi-user.target 

ファイルを保存して閉じ、Prometheus構成ディレクトリに適切な所有権と権限を設定します。

 chown -R prometheus:prometheus / etc / prometheus / 
chmod -R 775 / etc / prometheus /
chown -R prometheus:prometheus / var / lib / prometheus /

次に、systemdデーモンをリロードして、変更を適用します。

systemctlデーモン-リロード

次に、Prometheusサービスを開始し、次のコマンドを使用してシステムの再起動時に開始できるようにします。

 systemctl start prometheus 
systemctl enable prometheus

次のコマンドを使用して、プロメテウスのステータスを確認できます。

 systemctl status prometheus 

次の出力が得られます:

? prometheus.service-Prometheus Loaded:ロード済み(/etc/systemd/system/prometheus.service;無効;ベンダープリセット:有効)アクティブ:アクティブ(実行中)Sat 2021-10-16 14:06:39 UTC; 4秒前ドキュメント:https://prometheus.io/docs/introduction/overview/メインPID:18415(プロメテウス)タスク:5(制限:2341)メモリ:19.6M CPU:79ms Cグループ:/system.slice/prometheus.service ?? 18415 / usr / local / bin / prometheus --config.file =/ etc / prometheus / prometheus.yml --storage.tsdb.path =/ var / lib / prometheus --web.cons> Oct 16 14:06 :39 debian11 prometheus [18415]:level =info ts =2021-10-16T14:06:39.172Z caller =head.go:513 component =tsdb msg ="On-disk memory mappa> Oct 16 14:06:39 debian11 prometheus [18415]:level =info ts =2021-10-16T14:06:39.172Z caller =head.go:519 component =tsdb msg ="Replaying WAL、this> Oct 16 14:06:39 debian11 prometheus [18415] :level =info ts =2021-10-16T14:06:39.174Z caller =head.go:590 component =tsdb msg ="WALsegmentloaded">10月16日14:06:39debian11prometheus [18415]:level =info ts =2021-10-16T14:06:39.174Z caller =head.go:596 component =tsdb msg ="WAL replay complete> Oct 16 14:06:39 debian11 prometheus [18415]:level =info ts =2021-10 -16T14:06:39。 177Z caller =main.go:849 fs_type =EXT4_SUPER_MAGICOct 16 14:06:39 debian11 prometheus [18415]:level =info ts =2021-10-16T14:06:39.177Z caller =main.go:852 msg="TSDBが開始されました"10月16日14:06:39debian11プロメテウス[18415]:level =info ts =2021-10-16T14:06:39.178Z caller =main.go:979 msg="設定ファイルの読み込み"filenam>10月16日14:06 :39 debian11 prometheus [18415]:level =info ts =2021-10-16T14:06:39.178Z caller =main.go:1016 msg="設定の読み込みが完了しました>10月16日14:06:39debian11prometheus [18415] :level =info ts =2021-10-16T14:06:39.179Z caller =main.go:794 msg="サーバーはWeb要求を受信する準備ができています>10月16日14:06:39debian11prometheus [18415]:level =info ts =2021-10-16T14:06:39.179Z caller =tls_config.go:191 component =web msg="TLSが無効になっています>

デフォルトでは、Prometheusはポート9090でリッスンします。次のコマンドを使用して確認できます。

 ss -antpl | grep 9090 

次の出力が表示されます。

 LISTEN 0 4096 *:9090 *:* users:(( "prometheus"、pid =18415、fd =7))

終了したら、次のステップに進むことができます。

NginxをPrometheusのリバースプロキシとして構成する

次に、NginxをPrometheusのリバースプロキシとしてインストールして構成することをお勧めします。まず、次のコマンドを使用してNginxWebサーバーパッケージをインストールします。

 apt-get install nginx -y 

Nginxがインストールされたら、次のコマンドを使用してNginx仮想ホスト構成ファイルを作成します。

 nano /etc/nginx/conf.d/prometheus.conf 

次の行を追加します:

 server {listen 80; server_name prometheus.example.com;場所/{proxy_passhttp:// localhost:9090; proxy_http_version 1.1; proxy_set_headerアップグレード$http_upgrade; proxy_set_header接続'アップグレード'; proxy_set_header Host $ host; proxy_cache_bypass $ http_upgrade; }} 

ファイルを保存して閉じ、次のコマンドを使用して構文エラーがないかNginxを確認します。

 nginx -t 

すべてが正常であれば、次の出力が得られます:

 nginx:構成ファイル/etc/nginx/nginx.confテストが成功しました

最後に、Nginxサービスを再起動して、変更を適用します。

 systemctl restart nginx 

次のコマンドを使用して、Nginxサービスのステータスを確認することもできます。

 systemctl status nginx 

次の出力が得られるはずです:

? nginx.service-高性能Webサーバーとリバースプロキシサーバーロード済み:ロード済み(/lib/systemd/system/nginx.service;有効;ベンダープリセット:有効)アクティブ:アクティブ(実行中)2021-10-16土曜日以降14 :08:15 UTC; 2秒前ドキュメント:man:nginx(8)プロセス:18792 ExecStartPre =/ usr / sbin / nginx -t-q-gデーモンオン; master_process on; (code =exited、status =0 / SUCCESS)プロセス:18793 ExecStart =/ usr / sbin /nginx-gデーモンオン; master_process on; (code =exited、status =0 / SUCCESS)メインPID:18794(nginx)タスク:2(制限:2341)メモリ:2.5M CPU:35ms CGroup:/system.slice/nginx.service ?? 18794 nginx:マスタープロセス/ usr / sbin /nginx-gデーモンオン; master_process on; ?? 18795 nginx:worker processOct 16 14:08:15 debian11 systemd [1]:起動中高性能Webサーバーとリバースプロキシサーバー... Oct 16 14:08:15 debian11 systemd [1]:nginx.service:ファイル/run/nginx.pidからのPIDの解析に失敗しました:無効な引数Oct 16 14:08:15 debian11 systemd [1]:高性能Webサーバーとリバースプロキシサーバーを開始しました。

この時点で、Nginxがインストールされ、Prometheusにサービスを提供するように構成されています。これで、次のステップに進むことができます。

アクセスPrometheusダッシュボード

次に、Webブラウザーを開き、URL http://prometheus.example.comを使用してPrometheusダッシュボードにアクセスします。 。次のページが表示されます:

node_exporterのインストールと構成

node_exporterは、Prometheusサーバーのメトリックを監視および取得するエクスポーターです。まず、次のコマンドを使用して、node_exporterの最新バージョンをダウンロードします。

 wget https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz 

ダウンロードが完了したら、次のコマンドを使用してダウンロードしたファイルを抽出します。

 tar -xvzf node_exporter-1.2.2.linux-amd64.tar.gz 

次に、抽出したディレクトリを/ etc /prometheus/ディレクトリに移動します。

 mv node_exporter-1.2.2.linux-amd64 /etc/prometheus/node_exporter 

次に、次のコマンドを使用して適切な所有権を設定します。

 chown -R prometheus:prometheus / etc / prometheus / node_exporter 

次に、node_exporterサービスを管理するためのsystemdサービスファイルを作成します。

 nano /etc/systemd/system/node_exporter.service 

次の行を追加します:

 [Unit] Description =Node ExporterWants =network-online.targetAfter =network-online.target [Service] User =prometheusExecStart =/ etc / prometheus / node_exporter / node_exporter [Install] WantedBy =default.target 

ファイルを保存して閉じてから、systemdデーモンをリロードして変更を適用します。

systemctlデーモン-リロード

次に、node_exporterサービスを開始し、システムの再起動時に開始できるようにします。

 systemctl start node_exporter 
systemctl enable node_exporter

次のコマンドを使用して、node_exporterのステータスを確認できます。

 systemctl status node_exporter 

次の出力が得られます:

? node_exporter.service-ノードエクスポータロード済み:ロード済み(/etc/systemd/system/node_exporter.service;無効;ベンダープリセット:有効)アクティブ:Sun 2021-10-17 05:38:20 UTC以降アクティブ(実行中)。 4秒前メインPID:513(node_exporter)タスク:4(制限:2341)メモリ:4.7M CPU:11ms CGroup:/system.slice/node_exporter.service ?? 513 /etc/prometheus/node_exporter/node_exporterOct 17 05:38: 20 debian11 node_exporter [513]:level =info ts =2021-10-17T05:38:20.382Z caller =node_exporter.go:115 Collector =Thermal_zoneOct 17 05:38:20 debian11 node_exporter [513]:level =info ts =2021 -10-17T05:38:20.382Z caller =node_exporter.go:115 Collector =timeOct 17 05:38:20 debian11 node_exporter [513]:level =info ts =2021-10-17T05:38:20.382Z caller=node_exporter。 go:115 Collector =timexOct 17 05:38:20 debian11 node_exporter [513]:level =info ts =2021-10-17T05:38:20.382Z caller =node_exporter.go:115 Collector =udp_queuesOct 17 05:38:20 debian11 node_exporter [513]:level =info ts =2021-10-17T05:38:20.382Z caller =node_exporter.go:115 Collector =unameOct 17 05:38:20 debian11 node_exporter [513]:level =info ts =2021-10 -17T05:38:20.382Z caller =node_exporter.go:115 Collector =vmstatOct 17 05:38:20 debian11 node_exporter [513]:level =info ts =2021-10-17T05:38:20.382Z caller =node_exporter.go:115 Collector =xfsOct 17 05:38:20 debian11 node_exporter [513]:level =info ts =2021- 10-17T05:38:20.382Z caller =node_exporter.go:115 Collector =zfsOct 17 05:38:20 debian11 node_exporter [513]:level =info ts =2021-10-17T05:38:20.383Z caller =node_exporter.go :199 msg ="Listening on" address =:91> Oct 17 05:38:20 debian11 node_exporter [513]:level =info ts =2021-10-17T05:38:20.383Z caller =tls_config.go:191 msg =「TLSが無効になっています。」 http2 =false 

デフォルトでは、node_exporterはポート9100でリッスンします。次のコマンドで確認できます:

 ss -antpl | grep 9100 

次の出力が得られるはずです:

 LISTEN 0 4096 *:9100 *:* users:(( "node_exporter"、pid =513、fd =3))

node_exporterをPrometheusサーバーに追加します

次に、node_exporterをPrometheus構成ファイルに追加する必要があります。 Prometheusのデフォルト設定ファイルを編集することでそれを行うことができます:

 nano /etc/prometheus/prometheus.yml 

' scrape_configの下 '行、新しい job_nameを追加します 次の行を追加してnode_exporter。

 --job_name:'node_exporter' static_configs:-targets:['localhost:9100'] 

ファイルを保存して閉じてから、Prometheusサービスを再起動して変更を適用します。

 systemctl restart prometheus 

Prometheusとnode_exporterを確認します

次に、Prometheusダッシュボードに移動し、ステータス=>ターゲットをクリックします。 。次の画面にnode_exporterが表示されます。

ここで、Prometheusホームページに戻り、 node_memory_MemAvailable_bytesと入力します。 クエリフィールドで[実行]をクリックします ' ボタン。次の結果が得られます:

node_exporterを取得することもできます URLを使用したメトリクスデータhttp:// your-server-ip:9100 /metrics 以下に示すように:

結論

おめでとう!これで、Debian11にnode_exporterを使用してPrometheusが正常にインストールされました。ご不明な点がございましたらお気軽にお問い合わせください。詳細については、Prometheusの公式ドキュメントをご覧ください。


Debian
  1. Debian9にNagios4.3.xモニタリングツールをインストールする方法

  2. Debian9.2にIcinga2モニタリングツールをインストールする方法

  3. Debian10にosqueryをインストールする方法

  1. Nextcloud15をDebian9にインストールする方法

  2. Debian10にRethinkDBデータベースシステムをインストールする方法

  3. Debian10にラダーシステム監査ツールをインストールする方法

  1. Debian10にCactiSNMP監視ツールをインストールする方法

  2. Ubuntu20.04にPrometheusシステム監視ツールをインストールする方法

  3. PHP8をDebian11にインストールする方法