7.使用mysql_export監控mysql


ok,docker監控,宿主機CPU、磁盤、網絡、內存監控我們都已講過,是時候講一波mysql監控了。本次mysql部署在客戶端。

架構

客戶端

MySql安裝

##下載mysql的repo源:
[root@localhost ~]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
##安裝mysql-community-release-el7-5.noarch.rpm包:
[root@localhost ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
##安裝mysql:
[root@localhost ~]# yum install mysql-server -y
##修改權限,否則會報錯:
[root@localhost ~]# chown -R root:root /var/lib/mysql
##重啟mysql服務:
[root@localhost ~]# service mysqld restart
##登錄並重置密碼:
[root@localhost ~]# mysql -u root
mysql > use mysql;
mysql > update user set password=password('123456') where user='root';
mysql > exit;

mysqld_exporter安裝

##下載並解壓:
[root@localhost ~] wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gz
[root@localhost ~] tar -xvf mysqld_exporter-0.10.0.linux-amd64.tar.gz
##mysqld_exporter需要連接Mysql,首先為它創建用戶並賦予所需的權限:
[root@localhost ~]# mysql -u root -p123456
mysql >  GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'exporter'@'localhost' identified by '123456';
mysql >  GRANT SELECT ON performance_schema.* TO 'exporter'@'localhost';
mysql >  flush privileges;

創建.my.cnf文件

[root@localhost ~]vi .my.cnf

[client]
user=exporter
password=123456

進入mysqld_exporter的所在目錄,運行mysqld_exporter

./mysqld_exporter -config.my-cnf=".my.cnf" &

服務端

Prometheus配置

[root@localhost ~]vi /etc/prometheus/prometheus.yml
## 新增mysql監控
·······
### 新增對對docker容器的監控
  - job_name: 'docker'
    static_configs:
    - targets: ['192.168.229.139:9101','192.168.229.138:9101']  ## 目標主機

  - job_name: mysql
    static_configs:
      - targets: ['192.168.229.138:9104']

重啟Prometheus查看targets:

[root@localhost ~]# systemctl restart prometheus

grafana配置

下載MySQL_Overview.json
關於json文件如何導入,在第5節已經說過,這里不在多做贅述。導入成功后,如下所示:

軟件測試汪簡書地址
軟件測試汪博客地址

歡迎關注微信公眾號:軟件測試汪。軟件測試交流群:809111560

轉載請注意出處,謝謝合作


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM