文章目录
一、离线资源下载
Prometheus (x86监控服务器或者arm,我选了x86的)
官方下载页:https://prometheus.io/download/
选择 linux-amd64.tar.gz(x86架构)
备用地址(若官网无法访问):
Gitee镜像:https://gitee.com/mirrors/prometheus/releases
Node Exporter (ARM被监控服务器)
ARM版下载地址:https://prometheus.io/download/#node_exporter
选择 linux-armv7 或 linux-arm64 版本(根据ARM芯片类型)
Grafana (x86监控服务器)
官方二进制包:https://grafana.com/grafana/download
选择 linux-amd64.tar.gz[citation:9][citation:10]
RPM包(适用于CentOS/RedHat):
wget https://dl.grafana.com/oss/release/grafana-<版本号>.x86_64.rpm
⚠️ 操作建议:
在有网络的机器下载上述资源,通过U盘或内网传输至离线服务器。
版本选择:推荐 Prometheus v2.40+、Node Exporter v1.7+、Grafana v9.4+(兼容性最佳)。
二、部署步骤(x86监控服务器)
安装Prometheus
解压到/usr/local
tar -zxvf prometheus-*.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/prometheus-* /usr/local/prometheus
创建Systemd服务(避免手动启动)
cat /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
After=network.target
[Service]
User=prometheus
ExecStart=/usr/local/prometheus/prometheus \
--config.file=/usr/local/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动服务
useradd prometheus
mkdir /var/lib/prometheus
chown -R prometheus:prometheus /usr/local/prometheus /var/lib/prometheus
systemctl enable --now prometheus
systemctl status prometheus #检查启动状态
验证:访问 http://x86服务器IP:9090
安装Grafana
安装RPM包(CentOS/RedHat)
yum localinstall grafana-*.x86_64.rpm
或解压二进制包(通用Linux)
tar -zxvf grafana-*.linux-amd64.tar.gz -C /opt/grafana
创建Systemd服务(避免手动启动)
cat /etc/systemed/system/grafana.service
[Unit]
Description=Grafana
After=network.target
[Service]
User=grafana
Group=grafana
Type=simple
ExecStart=/opt/grafana/bin/grafana-server \
--config=/opt/grafana/conf/defaults.ini \
--homepath=/opt/grafana
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动服务
systemctl enable --now grafana-server
验证:访问 http://x86服务器IP:3000,默认账号 admin/admin
三、配置ARM被监控服务器
安装Node Exporter
解压ARM版Node Exporter
tar -zxvf node_exporter-*.linux-armv7.tar.gz -C /usr/local/
mv /usr/local/node_exporter-* /usr/local/node_exporter
创建Systemd服务
cat /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=node_exporter
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动服务
useradd node_exporter
systemctl enable --now node_exporter
验证:访问 http://ARM服务器IP:9100/metrics 查看指标
配置Prometheus抓取ARM节点
修改 prometheus.yml 添加ARM节点:
# 注意:yuml文件必须是空格,不能使用tab
scrape_configs:
- job_name: 'node'
static_configs:
- targets: ['192.168.1.101:9100', '192.168.1.102:9100'] # 直接填写目标 IP
relabel_configs:
# 将 instance 标签的值重写为 IP 地址
- source_labels: [__address__]
target_label: instance
replacement: '$1' # 保留 IP 部分(自动去除端口)
regex: '([^:]+):\d+'
修改后,可以使用以下命令来检查配置是否正确
./promtool check config prometheus.yml
重启Prometheus:
# 修改配置后,重启Prometheus
systemctl restart prometheus
# 检查Prometheus启动状态
systemctl status prometheus
四、Grafana可视化配置
添加数据源
登录Grafana → Configuration → Data Sources → 选择 Prometheus
URL填写 http://localhost:9090(Prometheus地址)
导入仪表盘
在Grafana中 → Dashboards → Import
输入模板ID 1860(官方Node Exporter仪表板,支持ARM指标)
或者在https://grafana.com/grafana/dashboards/?search=node+exporter,离线下载模板导入
关键注意事项
防火墙规则
开放x86服务器(监控服务器,也可以选择arm服务器,选择对应版本安装即可)的 9090(Prometheus)、3000(Grafana)端口。
开放ARM服务器的 9100(Node Exporter)端口
依赖项检查
ARM服务器需安装基础库:glibc、systemd(若缺失,需离线安装)
混合架构支持
Prometheus(x86)可同时监控x86和ARM节点,无需额外配置,被监控服务器要选择对应系统版本的node_exporter,其它无需特别配置。
配置成功如下图: