1.首先下载mysql-exporter
tar -xvf mysqld_exporter-0.10.0.linux-amd64.tar.gz
cd mysqld_exporter-0.10.0.linux-amd64
cp -ar mysqld_exporter /usr/local/bin/
chmod +x /usr/local/bin/mysqld_exporter
2.登陆mysql为mysql_exporter创建账号并授权
# 创建数据库用户。
mysql> CREATE USER 'mysql_exporter'@'localhost' IDENTIFIED BY 'Abcdef123!.';
# 对mysql_exporter用户授权
mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysql_exporter'@'localhost';
exit 退出mysql
3.创建mysql配置文件、运行时可免密码连接数据库:
cd mysqld_exporter-0.10.0.linux-amd64
cat my.cnf
[client]
user=mysql_exporter
password=Abcdef123!.
4.启动mysql_exporter客户端
nohup ./mysqld_exporter --config.my-cnf=./my.cnf &
mysqld_exporter的监听端口是9104
5.修改prometheus-cfg.yaml文件,添加如下:
- job_name: 'mysql'
static_configs:
- targets: ['192.168.124.16:9104']
kubectl apply -f prometheus-cfg.yaml
kubectl delete -f prometheus-deploy.yaml