Prometheus部署

导读:本篇文章讲解 Prometheus部署,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

Prometheus介绍

1、Prometheus 灵感来源与Google的Borgmon,主要用于近实时、基于动态云环境、容器的微服务、应用程序的监控。
Prometheus专注于当下正在发生的各类数据,而不是追踪数周以前的数据,因为他们认为“大多数监控查询以及告警等都是一天内的数据”,Facebook相关论文也验证了这一点:85%的时序查询是26小时之内的。

简单来概括,Prometheus是一个监控系统,并自带时序数据能力。

2、Prometheus是云原生计算基金会的一个项目,是一个系统和服务监控系统。它以给定的时间间隔从配置的目标收集指标,评估规则表达式,显示结果,并在观察到指定条件时触发警报。

将 Prometheus 与其他指标和监控系统区分开来的功能包括:

  • 多维数据模型(由指标名称和键/值维度集定义的时间序列)

  • PromQL,一种强大而灵活的查询语言,可利用这种维度

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

  • 用于时序收集的 HTTP拉取模型

  • 通过批处理作业的中间网关支持推送时序

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

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

  • 支持分层和水平联合

体系结构概述

Prometheus部署

prometheus 监控原理

1、prometheus :虽然说是监控平台,但是实际上是一套数据库

2、mysql_exporter: 可以理解成程序或者软件,他是工作在我们要监控的目标服务器上,主要是用于监控mysql的数据。

3、node_exporter: 他的作用主要是收集性能测试的数据,如cpu、内存磁盘网络等信息,然后将数据保存到prometheus,相当于将数据存入到数据库中。

4、prometheus 只能用于做数据存储,不能做展示,因此我们需要用到grafana组件。

5、grafana 主要是用于数据展示,并且可以做到定时读取数据

Prometheus部署

Prometheus部署

Prometheus下载地址

Grafana下载地址

基本环境

主机名称 IP地址 安装服务
master 192.168.91.137 prometheus
minion 192.168.91.138 node_exporter

准备工作

关闭防火墙和selinux

[root@master ~]# systemctl stop firewalld
[root@master ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@master ~]# setenforce 0
[root@master ~]# cat /etc/selinux/config 
SELINUX=disabled

安装Prometheus

// 下载安装包
[root@master ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.31.1/prometheus-2.31.1.linux-amd64.tar.gz

// 解压到/usr/local下
[root@master ~]# ls
anaconda-ks.cfg  prometheus-2.31.1.linux-amd64.tar.gz
[root@master ~]# tar xf prometheus-2.31.1.linux-amd64.tar.gz  -C /usr/local/
[root@master ~]# cd /usr/local/
[root@master local]# ls
bin    include  libexec                        share
etc    lib      prometheus-2.31.1.linux-amd64  src
games  lib64    sbin

// 重命名
[root@master local]# mv prometheus-2.31.1.linux-amd64/ prometheus
[root@master local]# ls
bin  games    lib    libexec     sbin   src
etc  include  lib64  prometheus  share

启动服务

[root@localhost local]# cd prometheus
[root@localhost prometheus]# ls
LICENSE  console_libraries  prometheus      promtool
NOTICE   consoles           prometheus.yml
[root@localhost prometheus]# /usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml"

查看端口

[root@localhost ~]# 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                 *:9090              *:* 

web页面访问
浏览器打开192.168.91.137:9090端口即可打开Prometheus自带的监控页面
Prometheus部署

Prometheus部署
http://192.168.91.137:9090/metrics 查看监控数据
Prometheus部署

开始监控

准备工作

// 关闭防火墙和selinux
root@minion ~]# systemctl stop firewalld
[root@minion ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@minion ~]# setenforce 0
[root@minion ~]# vim /etc/selinux/config 
SELINUX=disabled
下载node_exporter安装包
[root@minion ~]# wget https://github.com/prometheus/node_exporter/releases/download/v1.3.0/node_exporter-1.3.0.linux-amd64.tar.gz

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

// 解压
[root@minion ~]# tar xf node_exporter-1.3.0.linux-amd64.tar.gz -C /usr/local/
[root@minion ~]# cd /usr/local/
[root@minion local]# ls
bin    include  libexec                          share
etc    lib      node_exporter-1.3.0.linux-amd64  src
games  lib64    sbin

// 重命名
[root@minion local]# mv node_exporter-1.3.0.linux-amd64/ node_exporter
[root@minion local]# ls
bin  games    lib    libexec        sbin   src
etc  include  lib64  node_exporter  share

// 启动服务
[root@minion local]# cd node_exporter/
[root@minion node_exporter]# nohup /usr/local/node_exporter/node_exporter

// 查看服务
[root@minion ~]# 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                 *:9100              *:*

在prometheus配置文件添加受控主机

[root@localhost local]# cd prometheus/
[root@localhost prometheus]# ls
LICENSE  console_libraries  data        prometheus.yml
NOTICE   consoles           prometheus  promtool
[root@localhost prometheus]# 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: "amu1"
    static_configs:
      - targets: ["192.168.91.138:9100"]

服务重启

// 杀死进程,重新启动服务
[root@master prometheus]# pkill prometheus
[root@master prometheus]# /usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml"

重新访问web页面
Prometheus部署

Prometheus部署

安装grafana

// 下载rpm包
[root@master ~]# wget https://dl.grafana.com/oss/release/grafana-7.3.3-1.x86_64.rpm

[root@master ~]# ls
anaconda-ks.cfg
grafana-7.3.3-1.x86_64.rpm
prometheus-2.31.1.linux-amd64.tar.gz

[root@master ~]# yum -y install grafana-7.3.3-1.x86_64.rpm

// 启动服务
[root@master ~]# systemctl daemon-reload
[root@master ~]# systemctl enable --now grafana-server.service
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@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             [::]:*                                                                 
LISTEN 0      128                 *:3000              *:*                                                                 
LISTEN 0      128                 *:9090              *:*    

web页面访问

浏览器打开 192.168.91.137:3000 进入grafana界面
默认用户名密码都是 admin
初次登陆会提示修改密码

下面是重置密码界面
Prometheus部署

这是登录进去的界面
Prometheus部署
添加prometheus数据源
Prometheus部署
点击齿轮设置 的“Add data source”
Prometheus部署
url框内 输入 http://192.168.91.137:9090
Prometheus部署

Dashboards页面选择“Prometheus 2.0 Stats”,然后保存
Prometheus部署

点击放大镜 搜索 点进去第一个“Prometheus 2.0 Stats”即可看到整个监控页面

Prometheus部署
Prometheus部署

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之家整理,本文链接:https://www.bmabk.com/index.php/post/5590.html

(0)
小半的头像小半

相关推荐

极客之家——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!