深色模式
Grafana 安装与数据源
Prometheus 自带界面只够调试,真正做大盘要靠 Grafana。本文装好并接上 Prometheus。
适用环境
- Linux 服务器,能访问 Prometheus 的 9090 端口
- 建议与 Prometheus 同网段
bash
# 确认能访问 Prometheus
curl -s http://localhost:9090/-/ready1
2
2
操作步骤
1. 添加仓库并安装(Ubuntu/Debian)
bash
sudo apt-get install -y apt-transport-https
sudo tee /etc/apt/sources.list.d/grafana.list <<'EOF'
deb https://apt.grafana.com stable main
EOF
sudo apt-get update && sudo apt-get install -y grafana
sudo systemctl enable --now grafana-server1
2
3
4
5
6
2
3
4
5
6
2. 登录并改密码
浏览器访问 http://<IP>:3000,默认账号 admin/admin,首次登录强制改密码。
3. 添加 Prometheus 数据源
在 Web 中:Connections → Data sources → Add data source → Prometheus,填写:
URL: http://localhost:9090
Access: Server (default)1
2
2
点击 Save & test,出现 “Data source is working” 即成功。
4. 也可用配置文件预置
yaml
# /etc/grafana/provisioning/datasources/prom.yml
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
url: http://localhost:9090
isDefault: true1
2
3
4
5
6
7
2
3
4
5
6
7
验证
bash
curl -s http://localhost:3000/api/health1
在 Explore 里执行 up,能看到数据即链路打通。
常见坑
跨机访问用 Server 模式
数据源 Access 选 Server 时由 Grafana 后端去连 Prometheus;选 Browser 则由浏览器直连,注意网络可达性。
默认端口暴露公网风险
3000 端口默认无额外鉴权层,务必限制来源 IP 或放内网。