在做性能測(cè)試的時(shí)候難免會(huì)被定位搞得暈頭轉(zhuǎn)向,那么有一套好的監(jiān)控系統(tǒng)對(duì)于測(cè)試來(lái)說(shuō)那就是天眼,今天我們就來(lái)搭建一套監(jiān)控mysql數(shù)據(jù)庫(kù)的監(jiān)控系統(tǒng)?Grafana+Prometheus+MySQL+Mysqld_Exporter。
準(zhǔn)備工具:
MySQL:5.7
InfluxDB:1.7.9
Grafana:5.3.2
Prometheus:
Mysqld_Exporter:0.12.1
一.安裝MySQL
1.下載mysql5.7:wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
2.安裝客戶端:yum -y install mysql57-community-release-el7-10.noarch.rpm
3.安裝服務(wù)端:yum -y install mysql-community-server
4.啟動(dòng)mysql服務(wù):systemctl start ?mysqld.service
5.查看服務(wù)是否啟動(dòng):systemctl status mysqld.service
6.修改默認(rèn)密碼
進(jìn)入mysql的配置文件:vim /etc/my.cnf
添加如下信息
輸入命令重啟服務(wù):systemctl restart mysqld
執(zhí)行mysql進(jìn)入myslq命令行
修改密碼:
5.7之前:update user set password=password("123456") where user='root';
5.7之后:update mysql.user set authentication_string=password('123456') where user='root';
刷新:flush privileges;
退出:exit;
把/etc/my.cnf中的skip-grant-tables注釋再重啟服務(wù)
查看是否重啟成功
二.安裝mysqld_exporter
提前:在數(shù)據(jù)庫(kù)中創(chuàng)建監(jiān)控賬號(hào) 和密碼并授權(quán)
GRANT REPLICATION CLIENT,PROCESS,SELECT ON *.* TO qa_group@'127.0.0.1' identified by 'nF5kbr9Y6Jm1ZDQ7xTW0';
1.下載:wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
2.解壓 tar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz
3.重命名:mv mysqld_exporter-0.12.1.linux-amd64 ?mysqld_exporter
4.在root目錄下新建文件:.my.cnf
5.進(jìn)行.my.cnf文件配置
注意:user和password可以使用mysql的登錄用戶名和密碼也可以自己定義
6.啟動(dòng) 服務(wù)
7.瀏覽器輸入部署的ip+9104端口進(jìn)行測(cè)試,出現(xiàn)以下為啟動(dòng)成功
三.集成Grafana+prometheus
Grafana+prometheus在前面文章都安裝多,就不多說(shuō)啦,直接進(jìn)入配置過程
1.修改 vim prometheus.yml 配置文件 ?并重啟服務(wù)prometheus
2.下載mysql模板(7362)
3.新建prometheus數(shù)據(jù)源
來(lái)看一下監(jiān)控效果