
直接用二进制包启动,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」,确认 prometheus job 显示 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/prometheusservice 文件中 ExecStart 必须显式指定 –storage.tsdb.path,不能依赖默认值(默认是 ./data,即当前工作目录,而 systemd 的 WorkingDirectory 默认是根目录)
加 Node Exporter 采集主机指标,targets 一直显示 DOWN
不是 Prometheus 配错了,大概率是 Node Exporter 没跑起来,或网络不通。
排查顺序:
在 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 状态。

评论(0)