RHEL9.2部署Prometheus实战
RHEL 9.2 部署 Prometheus 完整实战(Zabbix 共存 + 3.x 踩坑记录)
环境:RHEL 9.2 x86_64 | Prometheus 3.13.5 LTS | 已有 Zabbix,新增 Prometheus
关键词:Prometheus、RHEL 9、Zabbix、监控、node_exporter、systemd
一、前言:已经有 Zabbix 了,为什么还要装 Prometheus
很多传统企业的监控现状是:Zabbix 跑了好几年,管着网络设备、存储、Windows 服务器和一堆老业务系统。这时候领导说要上 Prometheus,运维第一反应是——重复建设?
其实不是。这两套东西的能力边界差别很大:
| 维度 | Zabbix | Prometheus |
|---|---|---|
| 强项 | 网络设备 SNMP、无 Agent 监控、Web 界面配置、告警收敛 | 多维标签、PromQL 查询、容器/K8s、云原生生态 |
| 弱项 | 指标维度固定、查询能力弱、容器监控吃力 | 配置文件驱动、无 Web 配置界面、长期存储要额外做 |
务实的分工方案:
- Zabbix 继续管网络设备、交换机、存储、Windows、老业务系统
- Prometheus 管 Linux 主机,以及以后要上的容器平台
- 两套并行跑,端口不冲突,告警各自出
本文记录在 RHEL 9.2 上从零部署 Prometheus 的完整过程,包括一个官方文档都没提醒、但一定会踩的坑。
二、环境与版本选型
2.1 基础环境
cat /etc/redhat-release
# Red Hat Enterprise Linux release 9.2 (Plow)
uname -m
# x86_64
2.2 端口规划
单机部署,所有组件装一台,和已有的 Zabbix 完全错开:
| 组件 | 端口 | 作用 |
|---|---|---|
| Prometheus | 9090 | 时序数据库 + 指标抓取 |
| node_exporter | 9100 | 采集主机指标 |
| Alertmanager | 9093 | 告警路由 |
| Grafana | 3000 | 图表展示 |
| Zabbix Server(已有) | 10051 | 不冲突 |
| Zabbix Agent(已有) | 10050 | 不冲突 |
2.3 版本选择(重点)
2026 年 11 月的时间点,Prometheus 的版本情况是这样的:
| 版本 | 发布日期 | 支持截止 | 结论 |
|---|---|---|---|
| 3.16.0 | 2026-11-04 | 短期 | 非 LTS,几个月就 EOL |
| 3.15 | 2026-09-24 | 2026-11-06 | 已 EOL |
| 3.13.5(LTS) | 2026-10-21 | 2027-07-31 | 选这个 |
划重点:企业环境一定选 LTS 版本。3.15 发布才一个多月就已经停止安全支持了,追新版本在运维场景没有意义。
本文所有操作基于 Prometheus 3.13.5 LTS。
三、系统准备
3.1 时间同步
Prometheus 对时间极其敏感,时间漂移会导致指标乱序、查询结果异常。
timedatectl set-timezone Asia/Shanghai
systemctl enable --now chronyd
# 验证
chronyc sources -v
timedatectl
3.2 文件描述符上限
Prometheus 会打开大量文件句柄,默认的 1024 不够用。
cat >> /etc/security/limits.conf <<'EOF'
prometheus soft nofile 65536
prometheus hard nofile 65536
EOF
3.3 防火墙放行
firewall-cmd --permanent --add-port=9090/tcp # Prometheus
firewall-cmd --permanent --add-port=9100/tcp # node_exporter
firewall-cmd --permanent --add-port=9093/tcp # Alertmanager
firewall-cmd --permanent --add-port=3000/tcp # Grafana
firewall-cmd --reload
如果安全要求高,9100 建议限制来源 IP:
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.10/32" port port="9100" protocol="tcp" accept'
四、安装 Prometheus
4.1 创建用户和目录
useradd --no-create-home --shell /bin/false prometheus
mkdir -p /etc/prometheus /var/lib/prometheus
chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus
注意:数据目录一定要放
/var/lib/prometheus。这是 SELinux 的默认策略路径,放/opt或/home会踩到安全上下文问题,启动后写入失败还查不出原因。
4.2 下载并解压
cd /tmp
PROM_VERSION="3.13.5"
wget https://github.com/prometheus/prometheus/releases/download/v${PROM_VERSION}/prometheus-${PROM_VERSION}.linux-amd64.tar.gz
tar xzf prometheus-${PROM_VERSION}.linux-amd64.tar.gz
cd prometheus-${PROM_VERSION}.linux-amd64
内网无法访问 GitHub 的替代方案:
# 方案一:用 GitHub 代理
wget https://ghproxy.net/https://github.com/prometheus/prometheus/releases/download/v3.13.5/prometheus-3.13.5.linux-amd64.tar.gz
# 方案二:找一台能上网的机器下载后用 scp 传进来
scp prometheus-3.13.5.linux-amd64.tar.gz root@目标IP:/tmp/
4.3 ⚠️ 踩坑:consoles 目录不存在
按照网上大量 2.x 时代的教程,解压后会执行:
cp prometheus promtool /usr/local/bin/
cp -r consoles console_libraries /etc/prometheus/ # ← 这一行会报错
实际执行结果:
cp: cannot stat 'consoles': No such file or directory
cp: cannot stat 'console_libraries': No such file or directory
验证一下包里到底有什么:
ls -l
# prometheus
# promtool
# prometheus.yml
# LICENSE
# NOTICE
正确做法:跳过 consoles 那一步,只复制二进制和配置文件。
cd /tmp/prometheus-3.13.5.linux-amd64
cp prometheus promtool /usr/local/bin/
chmod 755 /usr/local/bin/prometheus /usr/local/bin/promtool
cp prometheus.yml /etc/prometheus/
chown -R prometheus:prometheus /etc/prometheus
# 验证
/usr/local/bin/prometheus --version
输出类似:
prometheus, version 3.13.5 (branch: HEAD, revision: ...)
build user: root@...
build date: 20261021-...
go version: go1.24.x
platform: linux/amd64
tags: netgo,builtinassets,stringlabels
4.4 配置文件
cat > /etc/prometheus/prometheus.yml <<'EOF'
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
monitor: 'rhel9-prometheus'
alerting:
alertmanagers:
- static_configs:
- targets:
- localhost:9093
rule_files:
- "rules/*.yml"
scrape_configs:
# Prometheus 自己
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
# 本机
- job_name: 'node-local'
static_configs:
- targets: ['localhost:9100']
labels:
instance_name: 'prometheus-server'
# 其他 Linux 主机(把 IP 换成你的)
- job_name: 'node-linux'
static_configs:
- targets:
- '192.168.1.11:9100'
- '192.168.1.12:9100'
labels:
env: 'prod'
EOF
mkdir -p /etc/prometheus/rules
chown -R prometheus:prometheus /etc/prometheus
4.5 systemd 服务
cat > /etc/systemd/system/prometheus.service <<'EOF'
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus \
--storage.tsdb.retention.time=30d \
--storage.tsdb.retention.size=50GB \
--web.listen-address=0.0.0.0:9090 \
--web.enable-lifecycle
SyslogIdentifier=prometheus
Restart=always
RestartSec=5
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now prometheus
systemctl status prometheus --no-pager
4.6 验证
curl -s http://localhost:9090/-/healthy
# 期望输出:Prometheus Server is Healthy.
ss -tlnp | grep 9090
# LISTEN 0 4096 0.0.0.0:9090 ...
journalctl -u prometheus -n 20 --no-pager
浏览器访问 http://服务器IP:9090,能看到 3.x 新版 UI 就说明服务正常。

五、安装 node_exporter
只装 Prometheus 没有意义,它本身不采集任何主机指标,需要配套的 exporter。
5.1 安装
Prometheus 服务器和每台被监控的 Linux 都要装。
cd /tmp
NE_VERSION="1.12.1"
wget https://github.com/prometheus/node_exporter/releases/download/v${NE_VERSION}/node_exporter-${NE_VERSION}.linux-amd64.tar.gz
tar xzf node_exporter-${NE_VERSION}.linux-amd64.tar.gz
cp node_exporter-${NE_VERSION}.linux-amd64/node_exporter /usr/local/bin/
chmod 755 /usr/local/bin/node_exporter
useradd --no-create-home --shell /bin/false node_exporter
5.2 systemd 服务
cat > /etc/systemd/system/node_exporter.service <<'EOF'
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter \
--collector.systemd \
--collector.processes \
--collector.diskstats \
--web.listen-address=0.0.0.0:9100
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now node_exporter
systemctl status node_exporter --no-pager
5.3 验证
# 能看到指标就说明正常
curl -s http://localhost:9100/metrics | head -20
# 检查关键指标是否存在
curl -s http://localhost:9100/metrics | grep -E 'node_cpu_seconds|node_memory_MemTotal|node_filesystem_avail'
–
更多推荐



所有评论(0)