zoukankan      html  css  js  c++  java
  • Grafana+Prometheus系统监控之MySql

    架构

    grafana和prometheus之前安装配置过,见:Grafana+Prometheus打造全方位立体监控系统

    MySql安装

    MySql的地位和重要性就不言而喻了,作为开源产品深受广大中小企业以及互联网企业喜爱,所以这里我们也有必要对其进行相应的监控。

    由于最近更换了CentOS7,这里对MySql重新安装一遍,顺便做个记录,CentOS7的yum源中默认好像是没有mysql的。为了解决这个问题,我们要先下载mysql的repo源。

    列出所有版本信息:

    lsb_release -a
    

    下载mysql的repo源:

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    

    安装mysql-community-release-el7-5.noarch.rpm包:

    rpm -ivh mysql-community-release-el7-5.noarch.rpm
    

    安装mysql:

     yum install mysql-server -y
    

    修改权限,否则会报错:

    chown -R root:root /var/lib/mysql
    

    重启mysql服务:

    service mysqld restart
    

    登录并重置密码:

    ## 直接回车进入mysql控制台
    mysql -u root
    mysql > use mysql;
    mysql > update user set password=password('123456') where user='root';
    mysql > exit;
    

    mysqld_exporter安装

    下载并解压:

    https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gz
    
    tar -xvf mysqld_exporter-0.10.0.linux-amd64.tar.gz
    

    mysqld_exporter需要连接Mysql,首先为它创建用户并赋予所需的权限:

     GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'exporter'@'localhost' identified by '123456';
     GRANT SELECT ON performance_schema.* TO 'exporter'@'localhost';
     flush privileges;
    

    创建.my.cnf文件 vi .my.cnf:

    [client]
    user=exporter
    password=123456
    

    运行mysqld_exporter:

    ./mysqld_exporter -config.my-cnf=".my.cnf" &
    

    Prometheus配置

    修改prometheus.yml加入MySql节点:

    global:
      scrape_interval:     15s
      evaluation_interval: 15s
    
    scrape_configs:
    
      - job_name: prometheus
        static_configs:
          - targets: ['localhost:9090']
            labels:
              instance: prometheus
    
      - job_name: linux1
        static_configs:
          - targets: ['192.168.1.120:9100']
            labels:
              instance: sys1
    
      - job_name: linux2
        static_configs:
          - targets: ['192.168.1.130:9100']
            labels:
              instance: sys2
    
      - job_name: redis1
        static_configs:
          - targets: ['192.168.1.120:9121']
            labels:
              instance: redis1
    
      - job_name: mysql
        static_configs:
          - targets: ['192.168.1.120:9104']
            labels:
              instance: db1
    

    保存以后重启Prometheus,查看targets:

    最后登录grafana查看MySql监控信息:

    参考文档:
    https://github.com/prometheus/mysqld_exporter

  • 相关阅读:
    LeetCode 189. Rotate Array
    LeetCode 965. Univalued Binary Tree
    LeetCode 111. Minimum Depth of Binary Tree
    LeetCode 104. Maximum Depth of Binary Tree
    Windows下MySQL的安装与配置
    LeetCode 58. Length of Last Word
    LeetCode 41. First Missing Positive
    LeetCode 283. Move Zeroes
    《蚂蚁金服11.11:支付宝和蚂蚁花呗的技术架构及实践》读后感
    删除docker下的镜像
  • 原文地址:https://www.cnblogs.com/smallSevens/p/7852980.html
Copyright © 2011-2022 走看看