当使用如下命令运行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
大功告成