JiaHe

相遇即是缘

手动安装

新增监控账号

mysql> create user mysql_exporter@'%' identified with mysql_native_password by 'mysql_exporter';
mysql> grant process, replication client, select on . to 'mysql_exporter'@'%';
mysql> flush privileges;

下载安装

# 官方下载地址:https://prometheus.io/download
tar -zxf mysqld_exporter-0.15.1.linux-amd64.tar.gz -C /opt
mv /opt/mysqld_exporter-0.15.1.linux-amd64/ /opt/mysqld_exporter
ln -s /opt/mysqld_exporter/mysqld_exporter /usr/local/bin/mysqld_exporter

# 配置文件
mkdir -o /etc/mysqld_exporter
cat > /etc/mysqld_exporter/mysql3306.yml <<EOF
[client]
host=localhost
user=mysql_exporter
password=mysql_exporter
port=3306
EOF

# 配置服务
cat > /usr/lib/systemd/system/mysqld_exporter.service <<EOF
[Unit]
Description=mysql_exporter
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/mysqld_exporter --config.my-cnf="/etc/mysqld_exporter/mysql3306.cnf" --web.listen-address=":9104"
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl start mysqld_exporter
systemctl enable mysqld_exporter
systemctl status mysqld_exporter

配置Prometheus

/opt/prometheus/prometheus.yml
- job_name: "MySQL"
static_configs:
- targets: ["IP:9104"]
# 重启prometheus
systemctl restart prometheus
systemctl status prometheus

配置Grafana

  1. 新增Dashboard
  2. 填写https://grafana.com/grafana/dashboards/7362
  3. 选择Prometheus
  4. 导入

MySQL Overview