本ブログはアフィリエイト広告を利用しています。

Prometheus systemd ユニットファイルでの起動に失敗

CentOS7でsystemdのユニットファイルに書いた設定が悪くてPrometheusの起動に失敗していたのでメモ

失敗した時にユニットファイル

失敗した時のログ

[root@localhost ~]# systemctl status prometheus.service -l
● prometheus.service - Prometheus
   Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2021-11-07 20:36:42 PST; 15min ago
  Process: 88338 ExecStart=/home/test/prometheus/prometheus-2.31.1.linux-amd64/prometheus (code=exited, status=2)
 Main PID: 88338 (code=exited, status=2)

Nov 07 20:36:42 localhost.localdomain systemd[1]: Started Prometheus.
Nov 07 20:36:42 localhost.localdomain prometheus[88338]: ts=2021-11-08T04:36:42.821Z caller=main.go:366 level=error msg="Error loading config (--config.file=prometheus.yml)" err="open prometheus.yml: no such file or directory"
Nov 07 20:36:42 localhost.localdomain systemd[1]: prometheus.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Nov 07 20:36:42 localhost.localdomain systemd[1]: Unit prometheus.service entered failed state.
Nov 07 20:36:42 localhost.localdomain systemd[1]: prometheus.service failed.

ユニットファイルはこちら

[Unit]
Description=Prometheus
After=syslog.target network.target

[Service]
Type=simple

ExecStart=/home/test/prometheus/prometheus-2.31.1.linux-amd64/prometheus
ExecStop=/bin/kill -INT $MAINPID

[Install]
WantedBy=multi-user.target

原因

上に書いたsystemctl statusにある通り、 “–config.file=prometheus.yml” がないことが原因です。
なのでユニットファイルのExecStartに追加してあげればOKです。

[Service]
Type=simple

ExecStart=/home/test/prometheus/prometheus-2.31.1.linux-amd64/prometheus --config.file=/home/test/prometheus/prometheus-2.31.1.linux-amd64/prometheus.yml
ExecStop=/bin/kill -INT $MAINPID

起動ログ

[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start prometheus.service
[root@localhost ~]# systemctl status prometheus.service -l
● prometheus.service - Prometheus
   Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2021-11-07 20:57:57 PST; 14s ago
 Main PID: 89101 (prometheus)
    Tasks: 6
   CGroup: /system.slice/prometheus.service
           mq89101 /home/test/prometheus/prometheus-2.31.1.linux-amd64/prometheus --config.file=/home/test/prometheus/prometheus-2.31.1.linux-amd64/prometheus.yml

Nov 07 20:57:58 localhost.localdomain prometheus[89101]: ts=2021-11-08T04:57:58.184Z caller=head.go:479 level=info component=tsdb msg="Replaying on-disk memory mappable chunks if any"
Nov 07 20:57:58 localhost.localdomain prometheus[89101]: ts=2021-11-08T04:57:58.184Z caller=head.go:513 level=info component=tsdb msg="On-disk memory mappable chunks replay completed" duration=4.22μs
Nov 07 20:57:58 localhost.localdomain prometheus[89101]: ts=2021-11-08T04:57:58.184Z caller=head.go:519 level=info component=tsdb msg="Replaying WAL, this may take a while"
Nov 07 20:57:58 localhost.localdomain prometheus[89101]: ts=2021-11-08T04:57:58.185Z caller=head.go:590 level=info component=tsdb msg="WAL segment loaded" segment=0 maxSegment=0
Nov 07 20:57:58 localhost.localdomain prometheus[89101]: ts=2021-11-08T04:57:58.185Z caller=head.go:596 level=info component=tsdb msg="WAL replay completed" checkpoint_replay_duration=12.23μs wal_replay_duration=107.119μs total_replay_duration=133.069μs
Nov 07 20:57:58 localhost.localdomain prometheus[89101]: ts=2021-11-08T04:57:58.185Z caller=main.go:866 level=info fs_type=XFS_SUPER_MAGIC
Nov 07 20:57:58 localhost.localdomain prometheus[89101]: ts=2021-11-08T04:57:58.185Z caller=main.go:869 level=info msg="TSDB started"
Nov 07 20:57:58 localhost.localdomain prometheus[89101]: ts=2021-11-08T04:57:58.185Z caller=main.go:996 level=info msg="Loading configuration file" filename=/home/test/prometheus/prometheus-2.31.1.linux-amd64/prometheus.yml
Nov 07 20:57:58 localhost.localdomain prometheus[89101]: ts=2021-11-08T04:57:58.188Z caller=main.go:1033 level=info msg="Completed loading of configuration file" filename=/home/test/prometheus/prometheus-2.31.1.linux-amd64/prometheus.yml totalDuration=2.514274ms db_storage=660ns remote_storage=3.28μs web_handler=130ns query_engine=510ns scrape=2.275134ms scrape_sd=31.66μs notify=22.59μs notify_sd=4.48μs rules=1.95μs
Nov 07 20:57:58 localhost.localdomain prometheus[89101]: ts=2021-11-08T04:57:58.188Z caller=main.go:811 level=info msg="Server is ready to receive web requests."

以上です。

コメント

タイトルとURLをコピーしました