prometheus数据源连不上最常见原因是url填错端口或协议(如误加/metrics路径);需确保仅填http://host:port,检查网络连通性、防火墙、scrape_interval配置及docker网络模式。

直接装官方包管理器源最稳,别碰二进制包除非你明确需要隔离部署;Prometheus 数据源 URL 填错端口或协议(比如写成 http://localhost:9090/metrics)是连不上最常见的原因。
用 apt/yum/dnf 装 Grafana 时必须做对三件事
Debian/Ubuntu 或 CentOS/RHEL 用户,跳过 tar.gz 解压方式——它不注册 systemd 服务、不自动建用户、配置路径分散,后续升级和排查反而更麻烦。
- 添加 GPG 密钥时,
gpg --dearmor输出路径必须是/usr/share/keyrings/grafana-stable-archive-keyring.gpg,少个-stable-或写成.asc后缀会导致apt-get update报 “NO_PUBKEY” 错误 - 仓库源里
arch=amd64不是可选参数,ARM64 机器要显式改成arch=arm64,否则apt会静默跳过该源 - 启动前务必执行
sudo systemctl daemon-reload,否则systemctl enable grafana-server会提示 unit file not found
Prometheus 数据源连不上?先盯住这四个点
“Save & test” 显示红色错误不是因为 Grafana 配置错了,大概率是网络或 Prometheus 自身没暴露好接口。
-
URL字段只填到http://host:port,不要带路径(如/api/v1/query),Grafana 会自动拼接 - 如果 Prometheus 运行在另一台机器,检查目标机的
firewalld或ufw是否放行了 9090 端口,curl -v http://target:9090/metrics能返回文本才说明通 - 确认 Prometheus 的
prometheus.yml里global.scrape_interval不为 0,否则服务虽运行但不拉取指标,Grafana 查不到任何 series - 若用 Docker 启动 Prometheus,宿主机访问需加
--network host或确保端口映射正确,localhost在容器内指自身,不是宿主机
插件加载失败基本都是 allow_loading_unsigned_plugins 没配对
社区插件(比如阿里云日志、华为云 LTS)默认被禁用,光解压到 plugins 目录没用,必须显式白名单。
- 路径要严格匹配:YUM 安装的 Grafana 配置文件是
/etc/grafana/grafana.ini,而 tar.gz 启动的是conf/defaults.ini或conf/custom.ini,改错文件无效 -
allow_loading_unsigned_plugins的值是插件目录名,不是 zip 包名,例如解压后得到aliyun-log-grafana-datasource-plugin-master,实际应填aliyun-log-grafana-datasource-plugin(去掉-master) - 多个插件用英文逗号分隔,不能有空格:
allow_loading_unsigned_plugins = plugin-a,plugin-b,写成plugin-a, plugin-b会只加载第一个
真正容易卡住的地方不在安装步骤本身,而在服务间网络可达性验证和配置项名称的精确匹配——比如 node_exporter 的 metrics 地址是 :9100/metrics,但 Grafana 连 Prometheus 时 URL 里绝不能出现 /metrics,这种细节错一个字符就白忙半小时。











