硬件监控:grafana+prometheus+node_exporter

一、前期准备:

grafana:前端展示平台,没有数据存储功能,但是,它有不同的展示模板,然后,把后端数据库中提供的数据,进行展示 -->展示数据

prometheus(普罗米修斯):时序数据库。数据库是存储数据,它的数据是有时间顺序。-->存数据(一般不放被测服务器)

exporter(数据收集):是通过exporter 来收集,收集不同监控数据,用不同 exporter。-->采集器(放在被测服务器上)

二、安装:prometheus

1、先启动grafana:

systemctl restart grafana-server

端口:3000

2、把 prometheus 的包上传到 非被测服务器上,即可

[root@centos7 ~]# cd /opt
[root@centos7 opt]# ls
grafana+prometheus
[root@centos7 opt]# cd grafana+prometheus/
[root@centos7 grafana+prometheus]# ls
grafana-7.4.3-1.x86_64.rpm                 nginx-vts-exporter-0.10.3.linux-amd64.
influxdb-1.7.0.x86_64.rpm                  node_exporter-1.1.1.linux-amd64.tar.gz
jmx_prometheus_javaagent-0.14.0.jar        prometheus-2.20.1.linux-amd64.tar.gz
mysqld_exporter-0.12.1.linux-amd64.tar.gz  redis_exporter-v1.17.1.linux-amd64.tar
nginx-module-vts.tar.gz                    tomcat.yml
[root@centos7 grafana+prometheus]# cd ..
[root@centos7 opt]# mkdir prometheus
[root@centos7 opt]# cd prometheus/
[root@centos7 prometheus]# ls
[root@centos7 prometheus]# ll
总用量 0
[root@centos7 prometheus]# mv /opt/grafana+prometheus/prometheus-2.20.1.linux-amd
[root@centos7 prometheus]# ll
总用量 63788
-rw-r--r--. 1 root root 65315813 7月  30 15:42 prometheus-2.20.1.linux-amd64.tar.
[root@centos7 prometheus]#

-->解压,进入解压后的 文件夹,prometheus.yml 这个文件,就是 prometheus 的配置文件

[root@centos7 prometheus]# tar -zxvf prometheus-2.20.1.linux-amd64.tar.gz
prometheus-2.20.1.linux-amd64/
prometheus-2.20.1.linux-amd64/LICENSE
prometheus-2.20.1.linux-amd64/NOTICE
prometheus-2.20.1.linux-amd64/tsdb
prometheus-2.20.1.linux-amd64/prometheus
prometheus-2.20.1.linux-amd64/console_libraries/
prometheus-2.20.1.linux-amd64/console_libraries/prom.lib
prometheus-2.20.1.linux-amd64/console_libraries/menu.lib
prometheus-2.20.1.linux-amd64/promtool
prometheus-2.20.1.linux-amd64/prometheus.yml
prometheus-2.20.1.linux-amd64/consoles/
prometheus-2.20.1.linux-amd64/consoles/node.html
prometheus-2.20.1.linux-amd64/consoles/prometheus-overview.html
prometheus-2.20.1.linux-amd64/consoles/prometheus.html
prometheus-2.20.1.linux-amd64/consoles/node-overview.html
prometheus-2.20.1.linux-amd64/consoles/index.html.example
prometheus-2.20.1.linux-amd64/consoles/node-disk.html
prometheus-2.20.1.linux-amd64/consoles/node-cpu.html
[root@centos7 prometheus]# ls
prometheus-2.20.1.linux-amd64  prometheus-2.20.1.linux-amd64.tar.gz
[root@centos7 prometheus]# cd prometheus-2.20.1.linux-amd64
[root@centos7 prometheus-2.20.1.linux-amd64]# ls
console_libraries  LICENSE  prometheus      promtool
consoles           NOTICE   prometheus.yml  tsdb
[root@centos7 prometheus-2.20.1.linux-amd64]# ls -l
总用量 153584
drwxr-xr-x. 2 3434 3434       38 8月   6 2020 console_libraries
drwxr-xr-x. 2 3434 3434      173 8月   6 2020 consoles
-rw-r--r--. 1 3434 3434    11357 8月   6 2020 LICENSE
-rw-r--r--. 1 3434 3434     3420 8月   6 2020 NOTICE
-rwxr-xr-x. 1 3434 3434 90933367 8月   6 2020 prometheus
-rw-r--r--. 1 3434 3434      926 8月   6 2020 prometheus.yml
-rwxr-xr-x. 1 3434 3434 51151585 8月   6 2020 promtool
-rwxr-xr-x. 1 3434 3434 15159115 8月   6 2020 tsdb

-->不做修改启动 ./prometheus  端口:9090

[root@centos7 prometheus-2.20.1.linux-amd64]# ./prometheus
level=info ts=2022-08-23T03:39:58.407Z caller=main.go:308 msg="No time or size retention was set so using the default time retention" duration=15d
level=info ts=2022-08-23T03:39:58.408Z caller=main.go:343 msg="Starting Prometheus" version="(version=2.20.1, branch=HEAD, revision=983ebb4a513302315a8117932ab832815f85e3d2)"
level=info ts=2022-08-23T03:39:58.408Z caller=main.go:344 build_context="(go=go1.14.6, user=root@7cbd4d1c15e0, date=20200805-17:26:58)"
level=info ts=2022-08-23T03:39:58.408Z caller=main.go:345 host_details="(Linux 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 centos7 (none))"
level=info ts=2022-08-23T03:39:58.408Z caller=main.go:346 fd_limits="(soft=1024, hard=4096)"
level=info ts=2022-08-23T03:39:58.408Z caller=main.go:347 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2022-08-23T03:39:58.453Z caller=main.go:684 msg="Starting TSDB ..."
level=info ts=2022-08-23T03:39:58.454Z caller=web.go:524 component=web msg="Start listening for connections" address=0.0.0.0:9090

3、安装采集器:收集硬件资源使用情况,所以,安装硬件资源的采集器:node_exporter

node_exporter安装与配置:

把包放到被收集的机器上解压,进入解压后的文件夹

[root@vircent7 ~]# cd /opt/
[root@vircent7 opt]# ls
apache-tomcat-8.5.56         containerd                 mysqldata
apache-tomcat-8.5.56.tar.gz  install_Docker_Mysql57.sh
[root@vircent7 opt]# mkdir exporter
[root@vircent7 opt]# cd exporter/
[root@vircent7 exporter]# ls
[root@vircent7 exporter]# ls
node_exporter-1.1.1.linux-amd64.tar.gz
[root@vircent7 exporter]# tar -xzvf node_exporter-1.1.1.linux-amd64.tar.gz
node_exporter-1.1.1.linux-amd64/
node_exporter-1.1.1.linux-amd64/LICENSE
node_exporter-1.1.1.linux-amd64/NOTICE
node_exporter-1.1.1.linux-amd64/node_exporter
[root@vircent7 exporter]# ls
node_exporter-1.1.1.linux-amd64  node_exporter-1.1.1.linux-amd64.tar.gz
[root@vircent7 exporter]# cd node_exporter-1.1.1.linux-amd64
[root@vircent7 node_exporter-1.1.1.linux-amd64]# ls
LICENSE  node_exporter  NOTICE
[root@vircent7 node_exporter-1.1.1.linux-amd64]# ./node_exporter

-->启动 ./node_exporter   端口:9100

nohup ./node_exporter &

[root@vircent7 node_exporter-1.1.1.linux-amd64]# nohup ./node_exporter &
[1] 2210
[root@vircent7 node_exporter-1.1.1.linux-amd64]# nohup: 忽略输入并把输出追加到"nohup.out"

4、prometheus 与 exporter(被监控的服务器)网络要通:

-->进入prometheus的机器上 执行:telnet node_exporter_ip 9100

[root@centos7 prometheus-2.20.1.linux-amd64]# telnet 192.168.72.133 9100
Trying 192.168.72.133...
Connected to 192.168.72.133.
Escape character is '^]'.

5、修改prometheus.yml配置文件:填写 exporter的服务信息(ip和端口)

[root@centos7 prometheus-2.20.1.linux-amd64]# vim prometheus.yml
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']

  - job_name: 'node_exporter'
    static_configs:
    - targets: ['192.168.72.133:9100']

-->启动prometheus:./prometheus   后台进程运行  nohup./prometheus&

[root@centos7 prometheus-2.20.1.linux-amd64]# nohup ./prometheus &
[1] 2031
[root@centos7 prometheus-2.20.1.linux-amd64]# nohup: 忽略输入并把输出追加到"nohup.out"

6、在grafana的web界面中,配置展示

http://grafana_ip:3000 admin admin

添加数据源 > 选择prometheus

name

HTTP-URL:http://prometheus_ip:9090

保存配置模板import > 12884

 

posted @ 2022-08-23 14:56  刑之风  阅读(236)  评论(0编辑  收藏  举报