一、下载并解压 node_exporter
cd /opt
# 下载最新版本(v1.8.1)
wget https://github.com/prometheus/node_exporter/releases/download/v1.8.1/node_exporter-1.8.1.linux-amd64.tar.gz
# 解压缩
tar -xvf node_exporter-1.8.1.linux-amd64.tar.gz
# 重命名
mv node_exporter-1.8.1.linux-amd64 node_exporter
# 可选:赋权
chmod +x /opt/node_exporter/node_exporter
二、创建 systemd 服务配置文件
sudo vim /etc/systemd/system/node_exporter.service
关键启动参数
[Unit]
Description=Prometheus Node Exporter
After=network.target
[Service]
User=nobody
ExecStart=/opt/node_exporter/node_exporter \
--collector.processes \
--collector.systemd \
--collector.logind \
--collector.cpu \
--collector.meminfo \
--collector.filesystem \
--collector.netstat \
--collector.netdev \
--collector.diskstats \
--collector.time \
--collector.uname \
--collector.loadavg
Restart=on-failure
[Install]
WantedBy=multi-user.target
三、启动并设置开机自启
# 重载 systemd 配置
sudo systemctl daemon-reload
# 设置开机启动
sudo systemctl enable node_exporter
# 启动服务
sudo systemctl start node_exporter
# 查看状态
sudo systemctl status node_exporter
四、验证是否成功
# 查看监听端口(默认9100)
ss -lntp | grep 9100
# 或访问
curl http://localhost:9100/metrics
# 验证某个采集器是否生效(例如 processes)
curl -s http://localhost:9100/metrics | grep node_processes
五、Prometheus 配置文件中添加目标
编辑你的 prometheus.yml
:
scrape_configs:
- job_name: 'node_exporter'
static_configs:
- targets: ['<你的服务器IP>:9100']
然后重启 Prometheus:
systemctl restart prometheus