prometheus node_exporter安装及grafana主机资源监控dashborad添加(yum版)

配置环境

系统: Ubuntu16 Centos7
软件: prometheus-2.8.0
  Grafana v6.0.1
  node_exporter 0.17.0

 

一、node_exporter安装配置

1.1 下载

sudo wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz
sudo mv node_exporter-0.17.0.linux-amd64.tar.gz /opt/
cd /opt/

1.2解压并启动

sudo tar xf node_exporter-0.17.0.linux-amd64.tar.gz 
sudo mv node_exporter-0.17.0.linux-amd64 /usr/local/node_exporter
cd /usr/local/node_exporter/
nohup ./node_exporter 2>&1 &
netstat -lntp # 查看9100端口

## 打开防火墙端口

sudo firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="47.244.158.55" port protocol="tcp" port="9100" accept"

sudo firewall-cmd --reload

1.3配置node-exporter开机自启

sudo vim /usr/lib/systemd/system/node-exporter.service

[Unit]
Description=Prometheus Node Exporter
After=network.target
 
[Service]
ExecStart=/usr/local/sbin/node_exporter
User=nobody
 
[Install]
WantedBy=multi-user.target


sudo cp -r node_exporter /usr/local/sbin/

添加开机自启动

sudo chkconfig --add node-exporter.service

centos7:

sudo systemctl enable node-exporter

二、配置prometheus-2.8.0

使用jumpserver登陆新前端new-prometheus

sudo vim /data/prometheus/conf/prometheus.yml

global:
  scrape_interval:     5s
  evaluation_interval: 5s
 
rule_files:
 
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']
  - job_name: '租用01公司前端服务器'
    file_sd_configs:
      - files: ['/data/prometheus/data/zy-01.yml']
        refresh_interval: 5s
  # 是否添加租用类型
  - job_name: '租用02公司前端服务器'
    file_sd_configs:
      - files: ['/data/prometheus/data/zy-02.yml']
        refresh_interval: 5s

cat /data/prometheus/data/cpgf.yml

- targets: ['<node_IP>:9100']
      labels:
          instance: <名称>

验证:

http://<IP>:9090/

修改prometheus.yml文件需要重启,修改data下面的yml文件不需要重启:


重启命令

sudo nohup ./opt/prometheus/prometheus --config.file /data/prometheus/conf/prometheus.yml --storage.tsdb.path /data --storage.tsdb.retention 30d --web.console.templates /opt/prometheus-2.8.0/consoles/ --web.console.libraries /opt/prometheus-2.8.0/console_libraries 2>&1 &

三、配置Grafana

访问:http://47.244.158.55:3000

点击“+” -->import-->输入8919

更改如下-->点击进口

点击设置图标

保留$maxmount

Json格式复制出来修改

替换$node

添加tags

完成

posted @ 2021-04-05 19:57  shuyang  阅读(204)  评论(0编辑  收藏  举报