简介:TG@luotuoemo
本文由腾讯云代理商【聚搜云】撰写
1. 安装Prometheus
-
下载并解压Prometheus:
bash
cd /opt wget https://github.com/prometheus/prometheus/releases/download/v3.2.0/prometheus-3.2.0.linux-amd64.tar.gz tar -xvzf prometheus-3.2.0.linux-amd64.tar.gz mv prometheus-3.2.0.linux-amd64 prometheus -
配置Prometheus的
prometheus.yml文件,添加监控目标:yaml
scrape_configs: - job_name: 'node' static_configs: - targets: ['localhost:9100'] -
启动Prometheus服务:
bash
./prometheus --config.file=prometheus.yml -
验证Prometheus是否运行正常,访问
http://localhost:9090。
2. 安装Node Exporter
-
下载并解压Node Exporter:
bash
cd /opt wget https://github.com/prometheus/node_exporter/releases/download/v1.9.0/node_exporter-1.9.0.linux-amd64.tar.gz tar -xvzf node_exporter-1.9.0.linux-amd64.tar.gz mv node_exporter-1.9.0.linux-amd64 node_exporter -
启动Node Exporter服务:
bash
./node_exporter -
验证Node Exporter是否运行正常,访问
http://localhost:9100/metrics。
3. 安装Grafana
-
安装Grafana:
bash
sudo yum install -y https://dl.grafana.com/oss/release/grafana-10.4.16-1.x86_64.rpm -
启动Grafana服务:
bash
sudo systemctl start grafana-server sudo systemctl enable grafana-server -
验证Grafana是否运行正常,访问
http://localhost:3000,默认用户名和密码均为admin。
4. 配置Grafana
-
登录Grafana后,添加Prometheus作为数据源:
- 进入“配置”->“数据源”。
- 选择“添加数据源”,选择
Prometheus。 - 填写Prometheus的URL。
-
保存并测试数据源,确保连接正常。
5. 创建仪表盘
- 进入
仪表盘->新建。 - 选择
Prometheus作为数据源。 - 输入PromQL语句,如
node_cpu_seconds_total,点击运行查看数据。 - 可以通过
导入模板快速创建仪表盘,选择一个模板ID并导入。