grafana+prometheus+node-exporter监控搭建与配置

2022/8/7 1:22:51

本文主要是介绍grafana+prometheus+node-exporter监控搭建与配置,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

前言

1、Grafana 是一个可视化工具,简单点说就是用来展示数据的。它和Zabbix、Prometheus 有本质区别,在于它不能解决监控问题,仅用于展示。也就是说,在监控领域,Grafana 需要配合 Zabbix、Prometheus 等工具一起使用,以获取数据源。

2、Prometheus 是一款基于时序数据库的开源监控告警系统。prometheus也可以使用传统二进制或是docker安装,为了便于配置,我这里使用传统的方式部署。

3、node-exporter用于提供*NIX内核的硬件以及系统指标,node-exporter用于采集服务器层面的运行指标,包括机器的loadavg、filesystem、meminfo等基础监控,类似于传统主机监控维度的zabbix-agent。

1、安装grafana

[10:02:09 root@libin3 ~]# mkdir grafana-prometheus                #创建一个用于数据持久化的文件夹

[10:02:09 root@libin3 ~]# chmod 777  grafana-prometheus/          #给予777权限

 

安装方式:注第1、2种方式都需要较长时间

方法1:

[10:06:02 root@libin3 grafana-prometheus]# cat grafana-install.sh

#!/bin/bash

wget wget https://dl.grafana.com/oss/release/grafana-6.4.4-1.x86_64.rpm

yum install -y grafana-6.4.4-1.x86_64.rpm

yum clean all

systemctl status grafana-server.service

systemctl daemon-reload

systemctl status grafana-server.service

netstat -tnlp | grep grafana

 

 

方法2:采用

[10:07:47 root@libin3 grafana-prometheus]# cat install.sh

#!/bin/bash

docker run -d \

  -p 3000:3000 \

  --name=grafana \

  --restart=always \

  --privileged=true \

  -v /opt/docker/grafana:/var/lib/grafana \

  grafana/grafana

 

 

方法3:我们采用清华大学开源软件镜像站https://mirrors.tuna.tsinghua.edu.cn/

[10:14:24 root@libin3 grafana-prometheus]#

wget https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/grafana-6.4.4-1.x86_64.rpm

注:如果是内网的情况下可以将RPM包上传至内网

 

[10:07:47 root@libin3 grafana-prometheus]# yum install -y grafana-6.4.4-1.x86_64.rpm  #进行安装

[10:07:47 root@libin3 grafana-prometheus]# systemctl start grafana-server.service

[10:07:47 root@libin3 grafana-prometheus]# systemctl status grafana-server.service

[10:07:47 root@libin3 grafana-prometheus]# systemctl daemon-reload

[10:07:47 root@libin3 grafana-prometheus]# netstat -tnlp | grep grafana

 

 

测试:访问grafana  默认用户名密码是admin/admin,考虑安全因素,第一次登录会要求你修改默认密码

 

 

 

2、安装prometheus

[10:14:24 root@libin3 grafana-prometheus]#  

wget https://mirrors.tuna.tsinghua.edu.cn/github-release/prometheus/prometheus/2.36.2%20_%202022-06-20/prometheus-2.36.2.linux-amd64.tar.gz

注:我们还是采用清华大学开源软件镜像站https://mirrors.tuna.tsinghua.edu.cn/

 

[10:14:24 root@libin3 grafana-prometheus]#  

tar -xf prometheus-2.36.2.linux-amd64.tar.gz && mv prometheus-2.36.2.linux-amd64 /usr/local/prometheus

解压

 

 

 

[10:14:24 root@libin3 grafana-prometheus]#  vim /usr/lib/systemd/system/prometheus.service

创建启动脚本,注如果需要指定端口运行,可以在ExecStart后指定端口,格式如下,默认为9090

--web.listen-address=:8008

 

[Unit]

Description=The Prometheus Server

After=network.target

 

[Service]

Restart=on-failure

ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml 

RestartSec=15s

 

[Install]

WantedBy=multi-user.target

 

 

 

[10:14:24 root@libin3 grafana-prometheus]# systemctl daemon-reload

[10:14:24 root@libin3 grafana-prometheus]# systemctl start prometheus

[10:14:24 root@libin3 grafana-prometheus]# systemctl enable prometheus

[10:14:24 root@libin3 grafana-prometheus]# systemctl status prometheus

 

 

查看服务prometheus状态正常

 

 

 

3、安装node-exporter

 

 

[10:14:24 root@libin3 grafana-prometheus]#

wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz

 

[10:14:24 root@libin3 grafana-prometheus]# tar -xf node_exporter-1.3.1.linux-amd64.tar.gz

 

 

[10:14:24 root@libin3 grafana-prometheus]# vim /usr/lib/systemd/system/node_exporter.service   #设置开启启动

[Unit]

Description=The Prometheus Node_Exporter

After=network.target

 

[Service]

Restart=on-failure

ExecStart=/usr/local/node_exporter/node_exporter --web.listen-address=:9100

RestartSec=15s

 

[Install]

WantedBy=multi-user.target

~                            

 

[10:14:24 root@libin3 grafana-prometheus]# systemctl daemon-reload

[10:14:24 root@libin3 grafana-prometheus]# systemctl start node_exporter

[10:14:24 root@libin3 grafana-prometheus]# systemctl enable node_exporter

[10:14:24 root@libin3 grafana-prometheus]# systemctl status node_exporter

 

 

[10:14:24 root@libin3 grafana-prometheus]#  vim /usr/local/prometheus/prometheus.yml   #配置prometheus

  - job_name: "node_exporter"

    static_configs:

      - targets: ["localhost:9100","192.168.124.134:9100"]

 

 

按照如上的格式配置,注意缩进。其中job_name可以任意,targets填写node_exporter的地址。修改好后保存退出。重启prometheus使配置生效

[10:14:24 root@libin3 grafana-prometheus]# systemctl restart prometheus

[10:14:24 root@libin3 grafana-prometheus]# systemctl status prometheus

[10:14:24 root@libin3 grafana-prometheus]# systemctl status node_exporter.service

[10:14:24 root@libin3 grafana-prometheus]# systemctl status grafana-server.service

[10:14:24 root@libin3 grafana-prometheus]# systemctl restart grafana-server.service

 

 

4、配置grafana

(1)grafana配置数据源和可视化模版来展示采集到的prometheus数据,登录后点击Data sources。

(2)增加数据源

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

注:到此grafana+prometheus+node-exporter监控搭建与基础配置已完成

 

 

 

 

 



这篇关于grafana+prometheus+node-exporter监控搭建与配置的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程