新手学习Prometheus设置为服务开机自启动时状态显示失败

文章讲述了用户在设置Prometheus开机自启动时遇到的问题,原因是配置文件中的路径与实际安装路径不符。解决方案包括修改配置文件的execstart路径或移动Prometheus二进制文件。最终通过systemctl命令成功重启并激活了Prometheus服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当使用如下命令运行Prometheus时可以成功访问ip+9090地址

./prometheus --config.file=/usr/local/prometheus/prometheus.yml

但是当设置开机自启动后,查看Prometheus状态

prometheus.service - logging prometheus service
   Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since 二 2023-08-08 16:17:38 CST; 2s ago
     Docs: https://prometheus.io
  Process: 8757 ExecStart=/usr/local/prometheus-2.46.0.linux-amd64/prometheus --config.file=/opt/prometheus/prometheus.yml (code=exited, status=2)
 Main PID: 8757 (code=exited, status=2)

 查看启动设置的配置文件

vim /etc/systemd/system/prometheus.service

发现配置文件中文件路径与本服务器安装路径不一致,即execstart后面的路径

ExecStart=/usr/local/prometheus/prometheus \
  --config.file=/usr/local/prometheus/prometheus.yml \
  --web.listen-address=:9090

两种解决方法,第一种是按照本服务器的文件地址修改上述文件execstart,或者将本服务器中的文件移动如下:

mv prometheus-2.46.0.linux-amd64/ prometheus

最后运行如下指令


[root@Prometheus prometheus]# systemctl daemon-reload
[root@Prometheus prometheus]# systemctl enable prometheus
[root@Prometheus prometheus]# systemctl start prometheus
[root@Prometheus prometheus]# systemctl status prometheus
 prometheus.service - Prometheus Monitoring System
   Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2023-08-08 16:22:20 CST; 4s ago
 Main PID: 8827 (prometheus)
   CGroup: /system.slice/prometheus.service
           └─8827 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.listen-address=:9090

大功告成 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值