• prometheus+grafana监控mysql


     

    prometheus+grafana监控mysql

    1、安装配置MySQL官方的 Yum Repository(有mysql只需设置监控账号即可)

    [root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
    [root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
    [root@localhost ~]# yum -y install mysql-community-server

    若安装失败可能和原有的mysql有冲突,卸载原有mysql:
    yum remove mariadb-config-3:10.1.20-2.el7.x86_64

    [root@localhost ~]# systemctl start  mysqld.service
    [root@localhost ~]# systemctl status mysqld.service

       此时MySQL已经开始正常运行,不过要想进入MySQL还得先找出此时root用户的密码,通过如下命令可以在日志文件中找出密码:

    [root@localhost ~]# grep "password" /var/log/mysqld.log

    如下命令进入数据库:
    [root@localhost ~]#mysql -uroot -p
    输入初始密码,此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库:(这里有个问题,新密码设置的时候如果设置的过于简单会报错:)
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

    mysql设置监控账号(要设置远程可连接)
    CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'password' WITH MAX_USER_CONNECTIONS 3;
    GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
    flush privileges;
    下面是我设置的远程连接步骤,请参考:
     1.登录MySQL
    mysql -uroot -proot
    2.进入数据库
    use mysql;
    3.查看是否有user表
    show tables;
    4.更改lost字段值
    update user set host='%' where host = 'localhost';
    5.刷新
    flush privileges;
    6.查看
    select host,user from user;
     

    2、mysql_exporter安装设置

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

    在安装包解压目录新增配置.my.cnf文件如下:

     

    启动
    ./mysqld_exporter --config.my-cnf=./.my.cnf &
    注意:
    需要保持9104端口局域网可以访问

    3、prometheus配置(安装prometheus的机器)

      prometheus配置如下:



     

    4、grafana操作(安装grafana的机器)

      Mysql主题下载地址:https://raw.githubusercontent.com/percona/grafana-dashboards/master/dashboards/MySQL_Overview.json

      其他主题下载地址:https://github.com/percona/grafana-dashboards

      下载好主题后进行主题导入即可。

     

     
  • 相关阅读:
    Windows编程系列:Windows中的消息
    python 日志 logging模块
    wx-xcx
    大坑:perspectiveTransform
    在移动硬盘上装系统
    Django
    双边滤波(Bilateral filter)
    Mesh Deformation with Laplacian Coordinates
    C++五十一篇 -- VS2017开发人员新闻无法联网
    idea 修改Git密码和账号后,Git提交账号的没有改变
  • 原文地址:https://www.cnblogs.com/JustinLau/p/11335750.html
Copyright © 2020-2023  润新知