Centos8 部署Promethus(普罗米修斯)+grafana画图

1. 普罗米修斯概述

Prometheus(由go语言(golang)开发)是一套开源的监控&报警&时间序列数 据库的组合。适合监控docker容器。

2. 时间序列数据

  1. 什么是序列数据

时间序列数据(TimeSeries Data) : 按照时间顺序记录系统、设备状态变化 的数据被称为时序数据。
应用的场景很多, 如:

气候的变化
某一个地区的各车辆的行驶轨迹数据
传统证券行业实时交易数据
实时运维监控数据等
  1. 时间序列数据特点

    性能好

关系型数据库对于大规模数据的处理性能糟糕。NOSQL可以比较好的处理 大规模数据,让依然比不上时间序列数据库。

存储成本低

高效的压缩算法,节省存储空间,有效降低IO
Prometheus有着非常高效的时间序列数据存储方法,每个采样数据仅仅占 用3.5byte左右空间,上百万条时间序列,30秒间隔,保留60天,大概花了 200多G(来自官方数据

3. 普罗米修斯特征

  1. 一个多维数据模型(时间序列由指标名称定义和设置键/值尺寸)

  2. 一个灵活的查询语言来利用这一维度

  3. 不依赖于分布式存储;单服务器节点是自治的

    扫描二维码关注公众号,回复: 13505055 查看本文章
  4. 时间序列收集通过HTTP 上的拉模型进行

  5. 通过中间网关支持推送时间序列

  6. 通过服务发现或静态配置发现目标

  7. 多种图形和仪表板支持模式

  8. 支持分层和水平联合

4. 普罗米修斯原理架构图

5. 部署普罗米修斯

实验环境:

主机名 服务器 IP地址
master Prometneus服务器 192.168.216.200
slave1 被监控服务器 192.168.216.210
grafana grafana服务器 192.168.216.215

环境准备,3台主机可联通外网

//3台主机均需要关闭防火墙,selinux
[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# systemctl disable firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@localhost ~]# vim /etc/selinux/config 
[root@localhost ~]# setenforce 0

5.1 安装prometheus

从官网下载相应的安装包https://prometheus.io/download/

[root@master ~]# ls
anaconda-ks.cfg  prometheus-2.31.1.linux-amd64.tar.gz

//解压到/usr/local
[root@master ~]# tar -zxvf  prometheus-2.31.1.linux-amd64.tar.gz -C /usr/local/

//改名字或者做软连接
[root@master ~]# cd /usr/local/
[root@master local]# mv prometheus-2.31.1.linux-amd64 prometheus
[root@master local]# ls
bin  etc  games  include  lib  lib64  libexec  prometheus  sbin  share  src

//使用默认配置文件启动
[root@master local]# /usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" 

//另外开一个终端查看端口号,9090就是默认端口号
[root@master ~]# ss -antl
State                  Recv-Q                 Send-Q                                 Local Address:Port                                 Peer Address:Port                Process                 
LISTEN                 0                      128                                          0.0.0.0:22                                        0.0.0.0:*                                           
LISTEN                 0                      128                                                *:9090                                            *:*                                           
LISTEN                 0                      128                                             [::]:22                                           [::]:*                    

5.2 prometheus web界面




6. 监控远程Linux主机

去之前的官网下载安装node_exporter组件

[root@slave1 ~]# ls
anaconda-ks.cfg  node_exporter-0.17.0.linux-amd64.tar.gz

//一样的解压,改名
[root@slave1 ~]# tar -zxvf node_exporter-0.17.0.linux-amd64.tar.gz -C /usr/local/
node_exporter-0.17.0.linux-amd64/
node_exporter-0.17.0.linux-amd64/NOTICE
node_exporter-0.17.0.linux-amd64/node_exporter
node_exporter-0.17.0.linux-amd64/LICENSE

[root@slave1 local]# mv node_exporter-0.17.0.linux-amd64/ node_exporter
[root@slave1 local]# ls
bin  etc  games  include  lib  lib64  libexec  node_exporter  sbin  share  src
[root@slave1 local]# cd node_exporter/
//就一个可执行文件,直接运行
[root@slave1 node_exporter]# ls
LICENSE  node_exporter  NOTICE

//这样运行不用开新终端
[root@slave1 node_exporter]# nohup /usr/local/node_exporter/node_exporter 
nohup: 忽略输入并把输出追加到'nohup.out'
[root@slave1 node_exporter]# ss -antl
State                  Recv-Q                 Send-Q                                 Local Address:Port                                 Peer Address:Port                Process                 
LISTEN                 0                      128                                          0.0.0.0:22                                        0.0.0.0:*                                           
LISTEN                 0                      128                                                *:9100                                            *:*                                           
LISTEN                 0                      128                                             [::]:22                                           [::]:*                                           
//确认端口9100正常运行

//在服务器上配置slave1,注意格式
[root@master ~]# vim /usr/local/prometheus/prometheus.yml 
.........- job_name: "prometheus"

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

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

 - job_name: "slave1"  //监控主机的别名
    static_configs:
      - targets: ['192.168.216.210:9100']  //ip+端口


//重启服务
[root@master ~]# pkill prometheus 
[root@master ~]# ss -antl
State                  Recv-Q                 Send-Q                                 Local Address:Port                                 Peer Address:Port                Process                 
LISTEN                 0                      128                                          0.0.0.0:22                                        0.0.0.0:*                                           
LISTEN                 0                      128                                             [::]:22                                           [::]:*                                           
[root@master ~]# /usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
[root@master local]# ss -antl
State                  Recv-Q                 Send-Q                                 Local Address:Port                                 Peer Address:Port                Process                 
LISTEN                 0                      128                                          0.0.0.0:22                                        0.0.0.0:*                                           
LISTEN                 0                      128                                                *:9090                                            *:*                                           
LISTEN                 0                      128                                             [::]:22                                           [::]:*             

回到服务器网页

7. 结合grafana画图

官网下载grafana
地址:https://grafana.com/grafana/download

[root@grafana ~]# ls
anaconda-ks.cfg  grafana-enterprise-8.2.5-1.x86_64.rpm

//安装
[root@grafana ~]# yum install -y grafana-enterprise-8.2.5-1.x86_64.rpm 

//启动服务并设置开机自启
[root@grafana ~]# systemctl enable --now grafana-server 
Synchronizing state of grafana-server.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable grafana-server
Created symlink /etc/systemd/system/multi-user.target.wants/grafana-server.service → /usr/lib/systemd/system/grafana-server.service.
[root@grafana ~]# ss -antl
State                  Recv-Q                 Send-Q                                 Local Address:Port                                 Peer Address:Port                Process                 
LISTEN                 0                      128                                          0.0.0.0:22                                        0.0.0.0:*                                           
LISTEN                 0                      128                                             [::]:22                                           [::]:*                                           
LISTEN                 0                      128                                                *:3000                                            *:*   
//默认端口为3000                      







猜你喜欢

转载自blog.csdn.net/weixin_46115601/article/details/121545198