prometheus配置自启
vim /lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System[Service]
ExecStart=/opt/prometheus-2.31.1.linux-amd64/prometheus --config.file=/opt/prometheus-2.31.1.linux-amd64/prometheus.yml --web.listen-address=:9090[Install]
WantedBy=multi-user.target
systemctl daemon-reload
接着重启和设置开机自启
systemctl restart prometheus.service
systemctl status prometheus.service
systemctl enable prometheus.service
如果想要不停机重载,可以设置脚本如下
vim reload.sh
#!/bin/bash
pid=$(ps -ef | grep prometheus | grep -v grep | awk '{print $2}')
kill -1 $pid
curl -XPOST http://30.37.137.250:9090/-/reload
重载时执行
sh reload.sh
如果重载报错Lifecycle API is not enabled.,可以在设置自启的位置后面加多一段参数
/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System[Service]
ExecStart=/opt/prometheus-2.31.1.linux-amd64/prometheus --config.file=/opt/prometheus-2.31.1.linux-amd64/prometheus.yml --web.listen-address=:9090 --web.enable-lifecycle[Install]
WantedBy=multi-user.target
最后执行服务命令即可
systemctl daemon-reload