架构图

环境

IP 环境 需装软件
192.168.0.237 mysql-5.7.20 node_exporter-0.15.2.linux-amd64.tar.gz
mysqld_exporter-0.10.0.linux-amd64.tar.gz
192.168.0.248 grafana+prometheus prometheus-2.1.0.linux-amd64.tar.gz
node_exporter-0.15.2.linux-amd64.tar.gz
grafana-4.6.3.linux-x64.tar.gz

在 192.168.0.248 上安装 grafana prometheus

安装 prometheus

  1. # 创建保存软件的目录
  2. mkdir /data/software/ -p
  3. cd /data/software/
  4. # 解压 prometheus
  5. tar xvf prometheus-2.1.0.linux-amd64.tar.gz -C /iba/
  6. cd /iba/
  7. mv prometheus-2.1.0.linux-amd64 prometheus
  8. cd prometheus/
  9. cp prometheus.yml /tmp/prometheus.yml.20181203
  10. # 配置 prometheus.yml
  11. cat prometheus.yml
  12. # my global config
  13. global:
  14. scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  15. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  16. # scrape_timeout is set to the global default (10s).
  17. # A scrape configuration containing exactly one endpoint to scrape:
  18. # Here it's Prometheus itself.
  19. scrape_configs:
  20. - job_name: 'Host'
  21. file_sd_configs:
  22. - files:
  23. - host.yml
  24. metrics_path: /metrics
  25. relabel_configs:
  26. - source_labels: [__address__]
  27. regex: (.*)
  28. target_label: instance
  29. replacement: $1
  30. - source_labels: [__address__]
  31. regex: (.*)
  32. target_label: __address__
  33. replacement: $1:9100
  34. - job_name: 'MySQL'
  35. file_sd_configs:
  36. - files:
  37. - mysql.yml
  38. metrics_path: /metrics
  39. relabel_configs:
  40. - source_labels: [__address__]
  41. regex: (.*)
  42. target_label: instance
  43. replacement: $1
  44. - source_labels: [__address__]
  45. regex: (.*)
  46. target_label: __address__
  47. replacement: $1:9104
  48. - job_name: 'prometheus'
  49. static_configs:
  50. - targets:
  51. - localhost:9090
  52. cat host.yml
  53. - labels:
  54. service: test
  55. targets:
  56. - 192.168.0.248
  57. - 192.168.0.237
  58. cat mysql.yml
  59. - labels:
  60. service: test
  61. targets:
  62. - 192.168.0.237
  63. # 测试 prometheus 是否可以正常启动
  64. /iba/prometheus/prometheus --storage.tsdb.retention=30d &
  65. ps -ef|grep prometh
  66. kill -9 14650
  67. # 配置 prometheus.service 文件
  68. vi /usr/lib/systemd/system/prometheus.service
  69. # 内容为
  70. [Unit]
  71. Description=Prometheus instance
  72. Wants=network-online.target
  73. After=network-online.target
  74. [Service]
  75. User=root
  76. Group=root
  77. Type=simple
  78. Restart=on-failure
  79. WorkingDirectory=/iba/prometheus/
  80. RuntimeDirectory=prometheus
  81. RuntimeDirectoryMode=0750
  82. ExecStart=/iba/prometheus/prometheus --storage.tsdb.retention=30d --config.file=/iba/prometheus/prometheus.yml
  83. LimitNOFILE=10000
  84. TimeoutStopSec=20
  85. [Install]
  86. WantedBy=multi-user.target
  87. # 启动 prometheus
  88. systemctl start prometheus
  89. systemctl status prometheus -l
  90. # 开放防火墙
  91. firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.0/16" accept"
  92. firewall-cmd --reload

浏览器输入 http://192.168.0.248:9090 访问

prometheus.yml 文件参考:

https://prometheus.io/docs/prometheus/latest/configuration/configuration/

https://prometheus.io/docs/prometheus/latest/configuration/configuration/#<relabel_config>

https://prometheus.io/docs/prometheus/latest/configuration/configuration/#<file_sd_config>

安装 node_exporter 获取主机信息

  1. # 解压 node_exporter
  2. cd /data/software/
  3. tar xf node_exporter-0.15.2.linux-amd64.tar.gz -C /usr/local
  4. mv node_exporter-0.15.2.linux-amd64 node_exporter
  5. nohup ./node_exporter &

安装 grafana

  1. cd /iba/software
  2. # 解压
  3. tar xf grafana-4.6.3.linux-x64.tar.gz -C /iba/prometheus/
  4. cd /iba/prometheus/
  5. mv grafana-4.6.3 grafana
  6. cd grafana/
  7. # 测试
  8. ./bin/grafana-server
  9. # 停止
  10. ctrl+c
  11. cat /usr/lib/systemd/system/grafana-server.service
  12. [Unit]
  13. Description=Grafana instance
  14. Documentation=http://docs.grafana.org
  15. Wants=network-online.target
  16. After=network-online.target
  17. [Service]
  18. User=root
  19. Group=root
  20. Type=simple
  21. Restart=on-failure
  22. WorkingDirectory=/iba/prometheus/grafana
  23. RuntimeDirectory=grafana
  24. RuntimeDirectoryMode=0750
  25. ExecStart=/iba/prometheus/grafana/bin/grafana-server
  26. LimitNOFILE=10000
  27. TimeoutStopSec=20
  28. [Install]
  29. WantedBy=multi-user.target
  30. # 启动
  31. systemctl start grafana-server
  32. systemctl status grafana-server -l

访问 http://192.168.0.248:3000,默认用户和密码是 admin/admin

配置数据源



下载 grafana-dashboards-1.6.1.tar.gz,解压,使用浏览器导入 dashboard, 下载地址:https://github.com/percona/grafana-dashboards/archive/v1.6.1.tar.gz





在 192.168.0.237 安装 node_exporter 和 mysqld_exporter

  1. cd /iba/software/
  2. tar zxf node_exporter-0.15.2.linux-amd64.tar.gz -C /usr/local/
  3. cd /usr/local/
  4. mv node_exporter-0.15.2.linux-amd64 node_exporter
  5. # 启动
  6. cd node_exporter/
  7. nohup ./node_exporter &

几分钟后 grafana 出现了新服务器的信息

在mysql上配置监控使用的用户

  1. GRANT REPLICATION CLIENT, PROCESS, SELECT ON *.* TO 'mysql_monitor'@'%' IDENTIFIED BY 'mysql_monitor';
  2. FLUSH PRIVILEGES;
  1. cd /iba/software/
  2. tar zxf mysqld_exporter-0.10.0.linux-amd64.tar.gz -C /usr/local/
  3. cd /usr/local/
  4. mv mysqld_exporter-0.10.0.linux-amd64/ mysqld_exporter
  5. cd mysqld_exporter/
  6. # 在 mysql 上创建一个专门用于监控的用户,
  7. cat .my.cnf
  8. [client]
  9. user=mysql_monitor
  10. password=mysql_monitor
  11. # 启动
  12. nohup /usr/local/mysqld_exporter/mysqld_exporter -config.my-cnf="/usr/local/mysqld_exporter/.my.cnf" &

导入 dashboard: MySQL_Overview.json

Grafan+Prometheus 监控 MySQL的更多相关文章

  1. Grafana+Prometheus 监控 MySQL

    转自:Grafana+Prometheus 监控 MySQL 架构图 环境 IP 环境 需装软件 192.168.0.237 mysql-5.7.20 node_exporter-0.15.2.lin ...

  2. Prometheus 监控Mysql服务器及Grafana可视化

    Prometheus 监控Mysql服务器及Grafana可视化. mysql_exporter:用于收集MySQL性能信息. 使用版本 mysqld_exporter 0.11.0 官方地址 使用文 ...

  3. 使用 Docker 部署 Grafana + Prometheus 监控 MySQL 数据库

    一.背景 在平时开发过程当中需要针对 MySQL 数据库进行监控,这里我们可以使用 Grafana 和 Prometheus 来实现监控功能.Grafana 是一款功能强大的仪表盘面板,支持多种数据源 ...

  4. 采用prometheus 监控mysql

    1. prometheus 是什么 开源的系统监控和报警工具,监控项目的流量.内存量.负载量等实时数据. 它通过直接或短时jobs中介收集监控数据,在本地存储所有收集到的数据,并且通过定义好的rule ...

  5. Grafana+Prometheus监控mysql性能

    #cmd /usr/local 今天讲一下如何监控服务器中的mysql数据库的性能 一.数据库操作 1.mysql启动 #service mysqld start #启动数据库 #service my ...

  6. Prometheus 监控MySQL

    目录 0.简介 1.mysql_exporter部署 2.mysql报警规则 0.简介 文中主要监控MySQL/MySQL主从信息 版本:mysql-5.7,mysql_exporter-0.12.1 ...

  7. 手把手教你使用 Prometheus 监控 MySQL 与 MariaDB.md

    概述 MySQL 是常用的关系型数据库,MariaDB 作为 MySQL 的分支版本,兼容 MySQL 协议,也越来越流行.在 Kubernetes 环境中如何使用 Prometheus 来对它们进行 ...

  8. prometheus监控mysql

    创建一个用于mysqld_exporter连接到MySQL的用户并赋予所需的权限 mysql> GRANT REPLICATION CLIENT, PROCESS ON *.* TO '; my ...

  9. 使用Prometheus监控SpringBoot应用

    通过之前的文章我们使用Prometheus监控了应用服务器node_exporter,数据库mysqld_exporter,今天我们来监控一下你的应用.(本文以SpringBoot 2.1.9.REL ...

随机推荐

  1. 开源播放器 ijkplayer (五) :Linux/Ubuntu 下编译ijkplayer

    一.安装Git与yasm sudo apt-get install git sudo apt-get install yasm 二.下载和配置 SDK.NDK SDK一般开发时肯定都有的,NDK一般是 ...

  2. 使用CSS样式的三种方式

    外部样式表 当样式需要被应用到很多页面的时候,外部样式表将是理想的选择.使用外部样式表,你就可以通过更改一个文件来改变整个站点的外观. 内部样式表 当单个文件需要特别样式时,就可以使用内部样式表.你可 ...

  3. eureka相关异常

    1. eureka相关异常 1.1. 异常信息 Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bea ...

  4. rabbitmq在ios中实战采坑

    1. rabbitmq在ios中实战采坑 1.1. 问题 ios使用rabbitmq连接,没过多久就断开,并报错.且用android做相同的步骤并不会报错,错误如下 Received connecti ...

  5. SpringBoot集成Thymeleaf模板引擎

    简单介绍 目前在JavaEE领域有几中比较常用的模板引擎,分别是Jsp.Velocity.Freemarker.Thymeleaf,对Freemark语法不是特别熟悉,不过对于前端页面渲染效率来说,j ...

  6. 电商门户网站商品品类多级联动SpringBoot+Thymeleaf实现

    在淘宝.京东等电商网站,其门户网站都有一个商品品类的多级联动,鼠标移动,就显示,因为前端不是我做的,所以不说明前端实现,只介绍后端实现. 搭建部署SpringBoot环境 配置文件配置: 开启了对Th ...

  7. java项目引用证书文件(微信支付的p12文件)

    1. 绝对路径: // windows: public static String PATH1 = "E:\\project27_app_wuyoujie\\apiclient_cert.p ...

  8. Spring Boot 2.1.0 已发布,7 个重大更新!

    距离<重磅:Spring Boot 2.0 正式发布!>已经过去大半年了,而 Spring Boot 2.1.0 在 10 月底就发布了,我们来看下 Spring Boot 2.1.0 都 ...

  9. openfire的SSL双向认证增加android客户端证书库步骤

    过程 需要新制作PKCS12证书库.CER证书.转换为androidBKS证书,最后把客户端的CER证书导入进im服务器的私钥库client.truststore,然后替换原证书.   新证书生成步骤 ...

  10. base64文件转MultipartFile文件

    在一些项目中,上传图片或者文件过大,这个时候我们就要选择压缩文件,压缩到我们指定的范围内在上传到服务器,当然压缩也是可以放到服务器进行操作的,但是考虑到前端传输时间问题,所以我们一般都是放到前端压缩后 ...