访问
- 打开
https://<SERVER_IP>:9090在您的浏览器中。 - 证书为自签名证书,因此浏览器会显示证书警告。
- Prometheus 的 targets 页面位于
https://<SERVER_IP>:9090/targets. - 指标位于
https://<SERVER_IP>:9090/metrics.
登录
Prometheus 受 HTTP Basic 认证保护。
- 用户名:
admin - 密码:存储在
/root/.prometheus-credentials
同一认证同时保护 Web UI、API 以及以下端点: /metrics 。
重要文件与目录
- Prometheus 配置:
/etc/prometheus/prometheus.yml - Web/TLS/认证配置:
/etc/prometheus/web-config.yml - TLS 证书:
/etc/prometheus/tls/ - Prometheus 数据:
/var/lib/prometheus - Node Exporter Textfile Collector:
/var/lib/node_exporter/textfile_collector - 凭据:
/root/.prometheus-credentials - Prometheus 二进制文件:
/usr/local/bin/prometheus - Promtool:
/usr/local/bin/promtool - Node Exporter 二进制文件:
/usr/local/bin/node_exporter - Prometheus 服务:
/etc/systemd/system/prometheus.service - Node Exporter 服务:
/etc/systemd/system/node_exporter.service
服务管理
检查 Prometheus:
systemctl status prometheus
重启 Prometheus:
systemctl restart prometheus
查看 Prometheus 日志:
journalctl -u prometheus -f
检查 Node Exporter:
systemctl status node_exporter
重启 Node Exporter:
systemctl restart node_exporter
查看 Node Exporter 日志:
journalctl -u node_exporter -f
添加 targets
编辑 /etc/prometheus/prometheus.yml:
vim /etc/prometheus/prometheus.yml
验证配置:
promtool check config /etc/prometheus/prometheus.yml
重新加载 Prometheus:
curl -sS --cacert /etc/prometheus/tls/prometheus.crt \
-u admin:<PASSWORD> \
-X POST https://localhost:9090/-/reload
保留
Prometheus 的配置如下:
- 保留时间:
30d - 最大存储大小:
10GB
以先达到的限制为准。
注意事项
- 未安装 Grafana 和 Alertmanager。可以单独添加并连接到此 Prometheus 实例。
- 指标最多保留 30 天或 10 GB,以先达到的限制为准。
- 自定义主机指标可以作为
.prom文件添加到以下目录:/var/lib/node_exporter/textfile_collector