首页 » 云自动化 » k8s » 正文

Kubernetes 1.8.6 集群部署–监控mysql(十四)

Grafana+Prometheus系统监控之MySql

架构

我写的这些笔记算是一个系列,所以都是接着上一篇一步步来切入的:

MySql安装

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

下载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('asd9577') where user='root';
mysql > exit;

mysqld_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.10.0.linux-amd64.tar.gz

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

GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'asd9577'@'localhost' identified by 'asd9577';

GRANT SELECT ON performance_schema.* TO 'asd9577'@'localhost';

flush privileges;

创建.my.cnf文件

vim /etc/my.cnf

[client]
user=asd9577
password=asd9577

运行mysqld_exporter:

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

Prometheus配置

修改prometheus.yml加入MySql节点,然后重启prometheus:

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.161.162:9100']
        labels:
          instance: sys1

  - job_name: linux2
    static_configs:
      - targets: ['192.168.161.163:9100']
        labels:
          instance: sys2
  - job_name: redis
    static_configs:
      - targets: ['192.168.161.162:9121']
        labels:
          instance: redis162
  - job_name: mysql
    static_configs:
      - targets: ['192.168.161.163:9104']
        labels:
          instance: db1

如上最后一条!

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

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

参考文档:

https://github.com/prometheus/mysqld_exporter

赞 (8)

本文共 4 个回复

  • jude 2018/05/24 09:29

    能提供一下mysql的grafana的dashboard吗?

    • zhdya 博主 2018/05/25 21:35

      @ jude 近期正在准备重新搭建一套可以我们重构线下的环境,之前的环境被我初始化掉了,你只要按照我之前的操作,一定会有mysql的dashboard在里面!!

  • jude 2018/05/23 19:08

    请问mysql的grafana dashboar在哪来可以下载?

    • zhdya 博主 2018/05/23 23:59

      @ jude 在我最初导入的模板中,涵盖Mysql_overview这个模板! 只需稍加配置即可!

发表评论