安装Mysql - Prometheus监控
安装
下载文件:
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.14.0/mysqld_exporter-0.14.0.linux-amd64.tar.gz
解压:
tar -zxvf mysqld_exporter-0.14.0.linux-amd64.tar.gz
创建Mysql用户名用于监控数据
CREATE USER 'mysql_node_exporter'@'localhost' IDENTIFIED BY '123456789';
grant select,replication client, process on *.* to 'mysql_node_exporter'@'localhost';创建配置文件:
vim /opt/sofeware/mysql_node_exporter/.my.cnf
[client]
user=mysql_node_exporter
password=123456789创建Service:
vim /etc/systemd/system/mysql_node_exporter.service
[Unit]
Description=mysql_node_exporter Monitoring System
Documentation=mysql_node_exporter Monitoring System
[Service]
Type=simple
ExecStart=/opt/sofeware/mysql_node_exporter/mysqld_exporter --config.my-cnf=/opt/sofeware/mysql_node_exporter/.my.cnf
Restart=on-failure
ExecStop=/bin/kill -INT $MAINPID
[Install]
WantedBy=multi-user.target设置启动项
systemctl daemon-reload
systemctl enable mysql_node_exporter.service
systemctl start mysql_node_exporter.service
systemctl status mysql_node_exporter.service查看端口是否启动:
netstat -lnptu | grep 9104
byz-db@database-server:~$ netstat -lnptu | grep 9104
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6 0 0 :::9104测试:
curl localhost:9104/metrics
成功::注意放行防火墙端口!!
配置Prometheus
修改Prometheus配置文件:vim /opt/sofeware/prometheus/prometheus.yml
scrape_configs: |
- 重启服务:
systemctl restart prometheus.service
配置Grafana
- 安装模板:MySQL Overview | Grafana Labs
- 导入模板:
点击Import即可! 之后查看效果:
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 Bai's Blog!