普罗米修斯数据库

一、Promethus(普罗米修斯)监控系统

  • 能够安装prometheus服务器
  • 能够通过安装node_exporter监控远程linux
  • 能够通过安装mysqld_exporter监控远程mysql数据库
  • 能够安装grafana
  • 能够在grafana添加prometheus数据源
  • 能够在grafana添加监控cpu负载的图形
  • 能够在grafana图形显示mysql监控数据

1.概述

Prometheus(由go语言(golang)开发)是一套开源的监控&报警&时间序列数据库的组合。适合监控docker容器。因为kubernetes(俗称k8s)的流行带动了prometheus的发展。


它的服务过程是这样的Prometheus daemon负责定时去目标上抓取metrics(指标) 数据,每个抓取目标需要暴露一个http服务的接口给它定时抓取。

Prometheus:支持通过配置文件、文本文件、zookeeper、Consul、DNS SRV lookup等方式指定抓取目标。支持很多方式的图表可视化,例如十分精美的Grafana,自带的Promdash,以及自身提供的模版引擎等等,还提供HTTP API的查询方式,自定义所需要的输出。

Alertmanager:是独立于Prometheus的一个组件,可以支持Prometheus的查询语句,提供十分灵活的报警方式。

PushGateway:这个组件是支持Client主动推送metrics到PushGateway,而Prometheus只是定时去Gateway上抓取数据

2.时间序列数据

时间序列数据(TimeSeries Data) : 按照时间顺序记录系统、设备状态变化的数据被称为时序数据。

特点:

  • 性能好

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

  • 成本低

    高效的压缩算法,节省存储空间,有效降低IO

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

特征:

  • 多维度数据模型
  • 灵活的查询语言(PromQL)
  • 不依赖分布式存储,单个服务器节点是自治的
  • 以HTTP方式,通过pull模型拉去时间序列数据
  • 也可以通过中间网关支持push模型
  • 通过服务发现或者静态配置,来发现目标服务对象
  • 支持多种多样的图表和界面展示

3.部署

从 //prometheus.io/download/ 下载相应版本,安装到服务器上官网提供的是二进制版,解压就能用,不需要编译。

#1.下载解压,添加环境变量 [root@gdx1 ~]#wget //github.com/prometheus/prometheus/releases/download/v2.25.0/prometheus-2.25.0.linux-amd64.tar.gz [root@gdx1 ~]# tar -xvf prometheus-2.25.0.linux-amd64.tar\(1\).gz -C /usr/local/ [root@gdx1 ~]# cd /usr/local/prometheus-2.25.0.linux-amd64/ [root@gdx1 prometheus-2.25.0.linux-amd64]# ll 总用量 167984 drwxr-xr-x 2 3434 3434 38 2月 18 00:11 console_libraries drwxr-xr-x 2 3434 3434 173 2月 18 00:11 consoles -rw-r--r-- 1 3434 3434 11357 2月 18 00:11 LICENSE -rw-r--r-- 1 3434 3434 3420 2月 18 00:11 NOTICE -rwxr-xr-x 1 3434 3434 91044140 2月 17 22:19 prometheus -rw-r--r-- 1 3434 3434 926 2月 18 00:11 prometheus.yml -rwxr-xr-x 1 3434 3434 80948693 2月 17 22:21 promtool [root@gdx1 prometheus-2.25.0.linux-amd64]# vim /etc/profile export PROMETHEUS_HOME=/usr/local/prometheus-2.25.0.linux-amd64 PATH=$PROMETHEUS_HOME:/bin export PATH [root@gdx1 prometheus-2.25.0.linux-amd64]# source /etc/profile

4.启动

[root@gdx1 ~]# cd /usr/local/prometheus-2.25.0.linux-amd64/ [root@gdx1 prometheus-2.25.0.linux-amd64]# ./prometheus --config.file="prometheus.yml"

5.监控远程Linux主机

#1.在远程主机(被监控端agent1)上安装node_exporter组件 [root@gdx2 ~]# tar xf node_exporter-1.1.1.linux-amd64.tar.gz -C /usr/local/ [root@gdx2 ~]# cd /usr/local/ [root@gdx2 local]# ll 总用量 0 drwxr-xr-x 2 3434 3434 56 2月 13 21:42 node_exporter-1.1.1.linux-amd64 [root@gdx2 local]# cd node_exporter-1.1.1.linux-amd64/ [root@gdx2 node_exporter-1.1.1.linux-amd64]# ll 总用量 18740 -rw-r--r-- 1 3434 3434 11357 2月 13 21:42 LICENSE -rwxr-xr-x 1 3434 3434 19170241 2月 13 21:31 node_exporter -rw-r--r-- 1 3434 3434 463 2月 13 21:42 NOTICE [root@gdx2 node_exporter-1.1.1.linux-amd64]# ./node_exporter #2.回到Prometheus服务器的配置文件里添加被监控机器的配置段 [root@gdx1 prometheus-2.25.0.linux-amd64]# vim prometheus.yml - job_name: 'Devops' static_configs: - targets: ['192.168.12.41:9100','192.168.12.12:9100'] #3.重启服务 [root@gdx1 ~]# cd /usr/local/prometheus-2.25.0.linux-amd64/ [root@gdx1 prometheus-2.25.0.linux-amd64]# ./prometheus --config.file="prometheus.yml" #注:可以通过浏览器访问`//被监控端IP:9100/metrics`就可以查看到node_exporter在被监控端收集的监控信息 #4.回到web管理界面 --> 点Status --> 点Targets --> 可以看到多了一台监控目标

pv : 页面浏览量 6千万
uv : 独立用户浏览量 3~4千
QPS :每秒查询率 5~10万

6.监控MySQL

#1.在被监控端(被监控端agent1)安装mysqld_exporter组件 注:此处使用k8smaster节点部署MySQL容器来监控 [root@gdx1 ~]# wget //github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz [root@gdx1 ~]# tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local/ [root@gdx1 ~]# cd /usr/local/mysqld_exporter-0.12.1.linux-amd64/ [root@gdx1 mysqld_exporter-0.12.1.linux-amd64]# ll 总用量 14484 -rw-r--r-- 1 3434 3434 11325 7月 29 2019 LICENSE -rwxr-xr-x 1 3434 3434 14813452 7月 29 2019 mysqld_exporter -rw-r--r-- 1 3434 3434 65 7月 29 2019 NOTICE #2.编写MySQL配置清单 部署pod [root@gdx1 yaml]# vim mysql.yaml kind: Deployment apiVersion: apps/v1 metadata: name: mysql spec: selector: matchLabels: app: mysql template: metadata: labels: app: mysql spec: nodeName: gdx1 containers: - name: mysql image: mysql:5.7 env: - name: MYSQL_ROOT_PASSWORD value: "123456" --- kind: Service apiVersion: v1 metadata: name: mysql spec: ports: - port: 3306 targetPort: 3306 nodePort: 30306 selector: app: mysql type: NodePort [root@gdx1 yaml]# kubectl apply -f mysql.yaml #3.进入容器授权 [root@gdx1 mysqld_exporter-0.12.1.linux-amd64]# kubectl exec -it mysql-7b8d8b5cb4-wqwx4 -- bash mysql> grant select,replication client,process ON *.* to 'mysql_monitor'@'%' identified by '123456'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) #4.编写启动配置文件 [root@gdx1 mysqld_exporter-0.12.1.linux-amd64]# vim .my.cnf [client] user=mysql_monitor password=123456 port=30306 #5.启动监控 [root@gdx1 mysqld_exporter-0.12.1.linux-amd64]# ./mysqld_exporter --config.my-cnf=".my.cnf" #6.回到Prometheus服务器的配置文件里添加被监控机器的配置段 - job_name: 'mysql' static_configs: - targets: ['192.168.12.11:9104'] #7.重启服务 [root@gdx1 prometheus-2.25.0.linux-amd64]# ./prometheus --config.file="prometheus.yml"

7.配置Grafana出图工具

1)什么是Grafana

Grafana是一个开源的度量分析和可视化工具,可以通过将采集的数据分析,查询,然后进行可视化的展示,并能实现报警。

2)使用Grafana连接Prometheus

#1.在grafana服务器上安装grafana。(此处选择k8s node节点) [root@gdx2 ~]# wget //dl.grafana.com/oss/release/grafana-7.4.3-1.x86_64.rpm [root@gdx2 ~]# sudo yum install grafana-7.4.3-1.x86_64.rpm [root@gdx2 ~]# tar xf grafana-7.4.3.linux-amd64.tar_\(2\).gz -C /usr/local/ #2.添加环境变量 [root@gdx2 grafana-7.4.3]# vim /etc/profile export GAFANA_HOME=/usr/local/grafana-7.4.3 PATH=$PATH:$GAFANA_HOME/bin export PATH [root@gdx2 grafana-7.4.3]# source /etc/profile #3.启动 [root@gdx2 grafana-7.4.3]# grafana-server 默认监控3000 浏览器访问ip+端口 默认密码:admin

3)添加数据源

4)查看数据

8.Grafana图形显示MySQL监控数据

1)在grafana上修改配置文件,并下载安装mysql监控的dashboard(包含相关json文件,这些json文件可以看作是开发人员开发的一个监控模板)

#1.下载mysql监控的dashboard [root@gdx2 ~]# git clone //github.com/percona/grafana-dashboards.git #2.修改grafana的配置文件 [root@gdx2 ~]# cd /usr/local/grafana-7.4.3/conf [root@gdx2 conf]# vim defaults.ini 在最后添加 [dashboards.json] enabled=true path=/var/lib/grafana/dashboards #3.将下载的mysql监控的dashboard里的所有内容移动到创建的dashboards下 [root@gdx2 conf]# mkdir -p /var/lib/grafana/dashboards [root@gdx2 ~]# cd /var/lib/grafana/dashboards/ [root@gdx2 dashboards]# cd .. [root@gdx2 grafana]# ll 总用量 0 drwxr-xr-x 2 root root 6 4月 18 21:07 dashboards [root@gdx2 grafana]# mv /root/grafana-dashboards/ . [root@gdx2 grafana]# ll 总用量 0 drwxr-xr-x 2 root root 6 4月 18 21:07 dashboards drwxr-xr-x 8 root root 272 4月 23 2021 grafana-dashboards [root@gdx2 grafana]# mv grafana-dashboards/dashboards/* dashboards/ [root@gdx2 grafana]# cd dashboards/ [root@gdx2 dashboards]# ll #查看所有json文件 总用量 9932 -rw-r--r-- 1 root root 24679 4月 23 2021 Advanced_Data_Exploration.json -rw-r--r-- 1 root root 76839 4月 23 2021 CPU_Utilization_Details.json -rw-r--r-- 1 root root 100017 4月 23 2021 Disk_Details.json ........ #4.重新启动 [root@gdx2 lib]# cd /usr/local/grafana-7.4.3/ [root@gdx2 grafana-7.4.3]# ll 总用量 28 drwxr-xr-x 2 root root 96 2月 24 19:56 bin drwxr-xr-x 3 root root 107 4月 18 21:06 conf [root@gdx2 grafana-7.4.3]# grafana-server -config ./conf/defaults.ini

2)导入json

Toplist

最新的帖子

標籤