mysqld_exporter是prometheus官方提供的用于监控mysql运行状态的exporter
系统 | 版本 |
---|---|
CentOS | 7.6.1810 (Core) |
CPU/内存 | 4核、8G |
mysqld_exporter | 0.14.0 |
mysql_exporter
官网
[root@A bag]# tar xf mysqld_exporter-0.14.0.linux-amd64.tar.gz
[root@A bag]# mv mysqld_exporter-0.14.0.linux-amd64 ../mysqld_exporter
my.cnf是mysqld_exporter的
[root@A bag]# cd ../mysqld_exporter
[root@A mysqld_exporter]# cat <> my.cnf
[client]
host = 192.168.1.10
port = 3306
user = exporter
password = exporter@123
[mysqladmin]
host = 192.168.1.10
port = 3306
user = exporter
password = exporter@123
EOF
登录进去数据库,进行授权
grant PROCESS,REPLICATION CLIENT,SELECT on *.* to 'exporter'@'192.168.1.10' identified by 'exporter@123' with grant option;
测试登录信息
mysql -u exporter -p'exporter@123' -h 192.168.1.10 -P 3306
分两种,任选一种,博主是第一种
yum install -y supervisor
systemctl enable supervisord --now
cat <<EOF>> /etc/supervisord.d/my.ini
[program:mysqld_exporter]
directory=/data/mysqld_exporter
command=/data/mysqld_exporter/mysqld_exporter --config.my-cnf=/data/mysqld_exporter/my.cnf --web.listen-address=0.0.0.0:9104 --collect.slave_status --collect.binlog_size --collect.info_schema.processlist --collect.info_schema.innodb_metrics --collect.engine_innodb_status --collect.perf_schema.file_events --collect.perf_schema.replication_group_member_stats
user=root
autostart=true
autorestart=true
startsecs = 2
redirect_stderr=true
stdout_logfile=/var/log/mysqld_exporter.log
EOF
# 加载配置
supervisorctl update
# 查看状态
supervisorctl status
cat <<EOF>> /usr/lib/systemd/system/mysqld-exporter.service
[Unit]
Description=mysqld_exporter
[Service]
User=root
ExecStart=/data/mysqld_exporter/mysqld_exporter --config.my-cnf /data/mysqld_exporter/my.cnf --web.listen-address=0.0.0.0:9104 \
--collect.slave_status \
--collect.binlog_size \
--collect.info_schema.processlist \
--collect.info_schema.innodb_metrics \
--collect.engine_innodb_status \
--collect.perf_schema.file_events \
--collect.perf_schema.replication_group_member_stats
Restart=on-failure
[Install]
WantedBy=multi-user.targe
EOF
systemctl daemon-reload
systemctl enable mysqld-exporter --now
systemctl status mysqld-exporter
systemctl stop mysqld-exporter
[root@A mysqld_exporter]# cat <> my3307.cnf
[client]
host = 192.168.1.10
port = 3307
user = exporter
password = exporter@123
[mysqladmin]
host = 192.168.1.10
port = 3307
user = exporter
password = exporter@123
EOF
grant PROCESS,REPLICATION CLIENT,SELECT on *.* to 'exporter'@'192.168.1.10' identified by 'exporter@123' with grant option;
测试登录信息
mysql -u exporter -p'exporter@123' -h 192.168.1.10 -P 3306
cat <<EOF>> /etc/supervisord.d/my3307.ini
[program:mysqld_exporter3307]
directory=/data/mysqld_exporter
command=/data/mysqld_exporter/mysqld_exporter --config.my-cnf=/data/mysqld_exporter/my33047.cnf --web.listen-address=0.0.0.0:9105 --collect.slave_status --collect.binlog_size --collect.info_schema.processlist --collect.info_schema.innodb_metrics --collect.engine_innodb_status --collect.perf_schema.file_events --collect.perf_schema.replication_group_member_stats
user=root
autostart=true
autorestart=true
startsecs = 2
redirect_stderr=true
stdout_logfile=/var/log/mysqld_exporter.log
EOF
# 加载配置
supervisorctl update
# 查看状态
supervisorctl status
ID: 7362
参考
scrape_configs:
- job_name: mysqld
static_configs:
- targets: ['192.168.1.10:9104']
prometheus部署
以上是centos上边部署mysqld_exporter监控数据库的方法,有问题联系博主,后续也有其他插件