赞
踩
[root@web02 /opt]# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
[root@web02 /opt]# mkdir /prometheus_mysql/
[root@web02 /opt]# tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /prometheus_mysql/
[root@web02 /opt]# cd /prometheus_mysql/
[root@web02 /prometheus_mysql]# mv mysqld_exporter-0.12.1.linux-amd64/* ./
[root@web02 /prometheus_mysql]# rm -rf mysqld_exporter-0.12.1.linux-amd64/
# 8.0之前
grant select,replication client,process ON *.* to 'mysql_monitor'@'localhost' identified by 'abc123';
# 8.0之后
create user 'mysql_monitor'@'localhost' identified by 'abc123';
grant select,replication client,process ON *.* to 'mysql_monitor'@'localhost';
#刷新权限
flush privileges;
# (注意:授权ip为localhost,因为不是prometheus服务器来直接找mariadb 获取数据,⽽是prometheus服务器找mysql_exporter,mysql_exporter 再找mariadb。所以这个localhost是指的mysql_exporter的IP)
[root@web02 ~]# cat /prometheus_mysql/.my.cnf
[client]
#host=192.168.15.8
#port=9104
user=mysql_monitor
password=abc123
[root@web02 /prometheus_mysql]# vim /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=prometheus server daemon
[Service]
ExecStart=/prometheus_mysql/mysqld_exporter --config.my-cnf=/prometheus_mysql/.my.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target
# 重载
[root@web02 /prometheus_mysql]# systemctl daemon-reload
[root@web02 ~]# systemctl enable mysqld_exporter.service --now
[root@web02 ~]# netstat -lntup|grep 9104
tcp6 0 0 :::9104 :::* LISTEN 2046/mysqld_exporte
[root@web02 ~]# curl 127.0.0.1:9104/metrics
[root@promethus ~]# vim /prometheus/prometheus.yml
...
- job_name: 'mysql-matomo'
static_configs:
- targets: ['192.168.15.8:9104']
[root@promethus ~]# systemctl restart prometheus.service
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。