Prometheus监控Mysql

Prometheus部署mysql_export

文章目录

  • Prometheus部署mysql_export

#下载mysql_exporter
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.14.0/mysqld_exporter-0.14.0.linux-amd64.tar.gz
#查看主机状态
[root@localhost /]# ls
bin   home   mnt                                        proc              run   tmp
boot  lib    mysqld_exporter-0.14.0.linux-amd64.tar.gz  prometheus_mysql  sbin  tyx
dev   lib64  node_exporter-1.5.0.linux-amd64.tar.gz     prometheus_node   srv   usr
etc   media  opt                                        root              sys   var
[root@localhost /]# ss -antl
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    Process    
LISTEN    0         80                   0.0.0.0:3306              0.0.0.0:*                  
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*                  
LISTEN    0         128                        *:9100                    *:*                  
LISTEN    0         128                     [::]:22                   [::]:*    

#解压
[root@localhost prometheus_mysql]# tar xf mysqld_exporter-0.14.0.linux-amd64.tar.gz  -C /prometheus_mysql/
[root@localhost prometheus_mysql]# mv /prometheus_mysql/mysqld_exporter-0.14.0.linux-amd64/* /prometheus_mysql/

#mysql创建监控用户并授权
mysql> create user 'mysql_monitor'@'localhost' identified by 'abc123';
Query OK, 0 rows affected (0.00 sec)

mysql>  grant select,replication client,process ON *.* to 'mysql_monitor'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

#创建客户端配置文件
[root@localhost prometheus_mysql]# vim .my.cnf
[root@localhost prometheus_mysql]# cat .my.cnf
[client]
user=mysql_monitor
password=abc123
[root@localhost prometheus_mysql]# 

#加入systemd管理
[root@localhost prometheus_mysql]# vim /usr/lib/systemd/system/mysqld_exporter.service
[root@localhost prometheus_mysql]# cat /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@localhost prometheus_mysql]# systemctl daemon-reload 
[root@localhost prometheus_mysql]# systemctl enable mysqld_exporter.service 
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld_exporter.service → /usr/lib/systemd/system/mysqld_exporter.service.


#启动
[root@localhost prometheus_mysql]# systemctl restart mysqld_exporter.service 
[root@localhost prometheus_mysql]# ss -antl
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    Process    
LISTEN    0         80                   0.0.0.0:3306              0.0.0.0:*                  
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*                  
LISTEN    0         128                        *:9100                    *:*                  
LISTEN    0         128                        *:9104                    *:*                  
LISTEN    0         128                     [::]:22                   [::]:*        

于server端加入监听端口

[root@localhost supervisory_control]# vim /prometheus/prometheus.yml 

static_configs:
            - targets: ["localhost:9090","192.168.245.130:9104","192.168.245.130:9100","192.168.245.129:9100"]


Prometheus监控Mysql_第1张图片

你可能感兴趣的:(mysql,prometheus,linux)