0
点赞
收藏
分享

微信扫一扫

Prometheus+Mysql监控

彪悍的鼹鼠 2021-09-26 阅读 69
  1. 下载 mysqld_exporter 在mysql被测服务器上
  1. 解压压缩包
tar zxvf mysqld_exporter-0.11.0.linux-amd64.tar.gz
  1. 改名并移动到指定目录
mv mysqld_exporter-0.11.0.linux-amd64 /usr/local/mysql_exporter
cd /usr/local/mysql_exporter
  1. 登录mysql为exporter创建账号并授权(可以直接使用已经创建的账号)
# 创建数据库用户。
mysql> CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'XXXXXXXX';
# 可查看主从运行情况查看线程,及所有数据库。
mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
  1. 创建 mysql_exporter 配置文件、运行时可免密码连接数据库
vim /usr/local/mysql_exporter/.my.cnf
[client]
host=pt-mysql1
port=3306
user=user_xxx
password=******
  1. 启动exporter客户端
./mysqld_exporter --config.my-cnf=.my.cnf
vim /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=mysqld_exporter
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter -config.my-cnf=/usr/local/mysqld_exporter/.my.cnf
Restart=on-failure

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start mysqld_exporter
systemctl status mysqld_exporter
systemctl enable mysqld_exporter # 设置开机启动
  1. 修改prometheus配置 prometheus.yml 添加监控目标
vim /usr/local/prometheus/prometheus.yml
 - job_name: mysql
static_configs:
- targets: ['192.168.*.**:9104']
labels:
group: mysqlgroup
  1. Grafana 可以使用官方推荐的模板直接显示,可以根据自己需求修改面板。

欢迎大家留言,一起讨论。

举报

相关推荐

0 条评论