文章目录
1、获取MySQL权限
前提:因为mysqld_exporter需要连接到MySQL,创建用户并赋予所需的权限。
mysql -uroot –p password #登录mysql,password是root密码
mysql> GRANT REPLICATION CLIENT,PROCESS ON *.* TO 'mysql_monitor'@'localhost' identified by 'mysql_monitor'; #创建mysql_monitor用户
mysql> GRANT SELECT ON *.* TO 'mysql_monitor'@'localhost'; #授权
如果出现以下错误,解决办法: set global validate_password_policy=LOW;
创建.my.cnf配置文件(可以放在任意位置,加载的时候路径对就ok):
vim .my.cnf
[client]
user=mysql_monitor
password=mysql_monitor
2、下载、解压、启动mysqld_exporter组件包:
该组件其他版本地址: https://github.com/prometheus/mysqld_exporter/releases
解压并启动mysqld_exporter:
tar –zxvf mysqld_exporter-0.12.1.linux-386.tar.gz
cd mysqld_exporter-0.12.1.linux-386.tar.gz
./mysqld_exporter --config.my-cnf="/home/prometheus_clusters_grafana/mysqld_exporter-0.12.1.linux-386/.my.cnf"
注:加载.my.cnf文件,路径一定要对!
3、查看MySQL指标
浏览器查看mysqld_exporter抓取到的mysql相关指标:http://xx.xx.xx.xx:9104/
4、在prometheus.yml配置需要监控的MySQL集群:
- job_name: 'mysql_exproter'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
# mysql_exporter组件
static_configs:
- targets: ['xx.xx.xx.10:9104',
'xx.xx.xx.11:9104',
'xx.xx.xx.12:9104',
'xx.xx.xx.13:9104',
]
5、验证mysqld_exporter在Prometheus配置
重启prometheus,在浏览器中验证mysqld_exporter是否配置成功。
./prometheus
http://xx.xx.xx.10:9090/targets(prometheus装在10主机节点上)
6、Grafana实现MySQL数据可视化
前提:配置好Prometheus数据源;掌握Grafana的简单使用!
相关链接: https://blog.csdn.net/weixin_42230348/article/details/108324882
Prometheus+mysqld_exporter打通之后,需要将mysqld_exporter抓取到的指标数据在Grafana实现可视化。
导入MySQL的Dashboard id:https://grafana.com/grafana/dashboards/11329
至此,Prometheus监控MySQL集群+Grafana实现可视化就完成了!!
有问题留言一起交流~~~