5分钟验证prometheus二进制包能否跑通:下载即用,前台启动确认配置可读、指标可拉、web界面(http://localhost:9090)可访问,重点排查路径权限、防火墙端口、data目录授权、yaml job_name唯一性及target地址准确性。

直接用二进制包启动,5分钟验证是否能跑通
Prometheus 不需要编译,下载即用。关键不是“装”,而是确认 prometheus 二进制文件能读配置、拉到指标、Web 界面可访问。
常见卡点:
-
prometheus.yml路径写错或权限不足(非 root 用户运行时,/usr/local/prometheus/下文件需对其可读) -
--web.listen-address=":9090"被防火墙拦截(CentOS 7+ 默认开 firewalld,需sudo firewall-cmd --add-port=9090/tcp --permanent && sudo firewall-cmd --reload) - 启动后日志里报
open /usr/local/prometheus/data: permission denied——说明没提前建好目录或没授权给运行用户
实操建议:
- 先用
sudo ./prometheus --config.file=prometheus.yml --web.listen-address=:9090 --storage.tsdb.path=./data前台启动,看控制台输出是否含Server is ready to receive web requests - 浏览器打开
http://localhost:9090,点菜单「Status」→「Targets」,确认prometheusjob 显示UP - 别急着配 systemd,先确保这一步能过;否则后续所有配置都白搭
配 systemd 服务时,User 和 data 目录权限必须匹配
systemd 启动失败最常因权限断在两处:User 字段指定的用户无法读配置、无法写 storage.tsdb.path。
典型错误现象:
-
systemctl status prometheus显示failed to create directory: mkdir /usr/local/prometheus/data: permission denied - 日志里反复出现
level=error msg="Error opening memory series storage" err="open /usr/local/prometheus/data: permission denied"
正确做法:
- 创建专用用户:
sudo useradd --no-create-home --shell /bin/false prometheus - 建数据目录并授权:
sudo mkdir -p /usr/local/prometheus/data && sudo chown -R prometheus:prometheus /usr/local/prometheus - service 文件中
ExecStart必须显式指定--storage.tsdb.path,不能依赖默认值(默认是./data,即当前工作目录,而 systemd 的 WorkingDirectory 默认是根目录)
加 Node Exporter 采集主机指标,targets 一直显示 DOWN
不是 Prometheus 配错了,大概率是 Node Exporter 没跑起来,或网络不通。
排查顺序:
Linux系统管理专家,覆盖12大模块:用户权限、SSH、存储、网络、systemd、防火墙、日志监控、备份恢复、TLS证书、Ansible、容器、IaC。提供配置、验证、加固、监控、备份、自动化、故障排查、回滚闭环。关键词:useradd、sudo、sshd_config、chmod、SEL...
- 在 Node Exporter 所在机器上执行
curl -s http://localhost:9100/metrics | head -n 3,能返回文本才说明服务真在监听 - 确认
node_exporter进程绑定的是0.0.0.0:9100,不是127.0.0.1:9100(后者只允许本机访问);启动时加--web.listen-address="0.0.0.0:9100" - 检查 Prometheus 配置里
targets写的是 Node Exporter 所在机器的真实 IP,不是localhost(除非两者在同一台) - 如果跨主机,用
telnet 172.16.2.101 9100测试连通性;失败则查目标机 firewalld 或云安全组
配置片段示例(prometheus.yml 中):
scrape_configs:
- job_name: 'node_exporter'
static_configs:
- targets: ['172.16.2.101:9100'] # 注意这里不是 localhost
prometheus.yml 里 scrape_configs 的 job_name 别重复
多个 job_name: 'prometheus' 会导致 Prometheus 启动失败,报错类似 duplicate job name "prometheus"。
这是 YAML 配置里最容易被忽略的硬约束:每个 job_name 必须全局唯一。
你可能会这样写:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'prometheus' # ❌ 错误:重复
static_configs:
- targets: ['192.168.1.10:9090']
正确方式是为不同实例起不同名字:
- job_name: 'prometheus-local'
static_configs:
- targets: ['localhost:9090']
- job_name: 'prometheus-remote'
static_configs:
- targets: ['192.168.1.10:9090']
另外注意:static_configs 是列表,但每个 job_name 只能有一个 static_configs 块;想加多个 target,写在同一个块里即可:
- job_name: 'node_exporter'
static_configs:
- targets: ['172.16.2.101:9100', '172.16.2.102:9100'] # ✅ 正确
真正麻烦的从来不是下载和解压,而是权限路径对不上、端口被拦住、YAML 缩进错位、target 写成 localhost 却跨机器——这些细节不逐条核对,Prometheus 就永远停在 DOWN 状态。










