Prometheus+Grafana+mysqld_exporter 监控 MySQL
Prometheus Grafana DevOps About 2,049 words创建用户
仅限本机登录
CREATE USER 'exporter'@'localhost' IDENTIFIED BY '123456' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
限制指定IP
登录
CREATE USER 'exporter'@'192.168.0.100' IDENTIFIED BY '123456' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'192.168.0.100';
限制指定网段登录
CREATE USER 'exporter'@'192.168.0.%' IDENTIFIED BY '123456' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'192.168.0.%';
任意主机都可登录
CREATE USER 'exporter'@'%' IDENTIFIED BY '123456' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%';
下载 mysqld_exporter
https://github.com/prometheus/mysqld_exporter/releases
新建配置文件
命名为my.cnf
。
[client]
host=192.168.0.100
port=3306
user=exporter
password=123456
后台启动
nohup /root/exporter/mysqld_exporter-0.13.0/mysqld_exporter --config.my-cnf="my.cnf" > mysqld_exporter.out 2>&1 &
设置开机启动
编辑
vim /etc/systemd/system/mysqld_exporter.service
内容:ExecStart
需要修改为mysqld_exporter
二进制文件的绝对路径
[Unit]
Description=mysqld_exporter
Documentation=https://github.com/prometheus/mysqld_exporter
After=network.target
[Service]
Type=simple
User=root
ExecStart= /root/exporter/mysqld_exporter-0.13.0/mysqld_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
设为开机启动
sudo systemctl enable mysqld_exporter.service
启动mysqld_exporter
sudo systemctl start mysqld_exporter.service
mysqld_exporter 默认端口
修改 Prometheus 配置
scrape_configs
下新增job_name
为mysql
(名称随意)
- job_name: 'mysql'
static_configs:
- targets: ['192.168.0.100:9104']
完整的scrape_configs
如下
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: 'mysql'
static_configs:
- targets: ['192.168.0.100:9104']
重启 Prometheus
重启后可查看mysqld_exporter
是否上线。
Grafana Dashboard
MySQL Overview: https://grafana.com/grafana/dashboards/7362
开源地址
Views: 2,116 · Posted: 2022-02-22
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...