共計 3220 個字符,預計需要花費 9 分鐘才能閱讀完成。
這篇文章給大家分享的是有關 Mysql 中 Anemometer 怎么用的內容。丸趣 TV 小編覺得挺實用的,因此分享給大家做個參考,一起跟隨丸趣 TV 小編過來看看吧。
準備條件:
1.MySQL 開啟慢查詢
2. 安裝 Percona Toolkit
rpm -qa|grep percona
percona-toolkit-2.2.7-1
3. 下載 Anemometer
官網:https://github.com/box/Anemometer
4. 準備好 php 相關模塊 (或者 yum)
5. 啟動 apache 服務
rpm -qa|grep http
httpd-2.2.3-45.el5
安裝:
1. 安裝 Percona Toolkit:
rpm -ivh percona-toolkit-2.2.7-1.noarch.rpm
2. 將 Anemometer 文件包解壓,重命名為 anemometer,并移動到 /var/www/html 下 (apache 默認路徑)
pwd
/var/www/html/anemometer
3. 安裝 php 相關模塊:
rpm -qa|grep php
php53-common-5.3.3-1.el5
php53-bcmath-5.3.3-1.el5
php53-mysql-5.3.3-1.el5
php53-dba-5.3.3-1.el5
php53-cli-5.3.3-1.el5
php53-gd-5.3.3-1.el5
php53-5.3.3-1.el5
php53-pdo-5.3.3-1.el5
NOTE:
PHP 版本要大于 5.3,否則就報錯,如:
Anemometer requires PHP 5.3 or newer. You have 5.1.6
除此之外還需要:bcmath
rpm -qa|grep bcmath
php53-bcmath-5.3.3-1.el5
4. 執行 setup 腳本,創建用戶:
[root@/var/www/html/anemometer]mysql -uroot -pxxx install.sql
[root@/var/www/html/anemometer]mysql -uroot -pxxx
mysql grant all on slow_query_log.* to anemometer @ % identified by test
mysql grant select on *.* to anemometer @ %
mysql grant all on slow_query_log.* to anemometer @ localhost
mysql grant select on *.* to anemometer @ localhost
5. 將慢查詢日志通過 pt-query-digest 分析后存入數據庫中:
pt 版本小于 2.2 版本的語句:
pt-query-digest –user=anemometer –password=test \
–review h=db.example.com,D=slow_query_log,t=global_query_review \
–review-history h=db.example.com,D=slow_query_log,t=global_query_review_history \
–no-report –limit=0% \
–filter= \$event- {Bytes} = length(\$event- {arg}) and \$event- {hostname}=\ $HOSTNAME\ \
/root/test/localhost-slow.log
pt 版本大于 2.2 版本的語句:
pt-query-digest –user=anemometer –password=test –review h=hd-119-186,D=slow_query_log,t=global_query_review –history h=hd-119-186,D=slow_query_log,t=global_query_review_history –no-report –limit=0% –filter= \$event- {Bytes} = length(\$event- {arg}) and \$event- {hostname}=\ $HOSTNAME\ /root/test/localhost-slow.log
執行這個操作后,將會把慢日志分析后存入 mysql 的 slow_query_log 數據庫。
NOTE:
記得保證相應 用戶 @ 主機 的訪問權限
6. 修改可視界面的配置信息:
cd /var/www/html/anemometer/conf
cp sample.config.inc.php config.inc.php
vi config.inc.php
以及:
NOTE:
主機名一定要修改正確,不能保留為 localhost,否則會導致最終界面無法訪問。
7. 最終本地通過 IP 訪問:
http://192.168.44.130/anemometer
查詢后可獲得慢查詢日志的結果:
補充:如何監控多個數據庫 [root@RZ-SI1-DB-14 conf]# ll
total 40
-rwxr-xr-x 1 root root 15504 Oct 12 14:51 config.inc.php ### 新版都不需要修改里面的配置了,只需要修改下面的 datasource
-rwxrwxrwx 1 root root 314 Oct 12 14:54 datasource_si1.inc.php
-rwxr-xr-x 1 root root 314 Oct 12 15:05 datasource_st1.inc.php — 配置多個 datasource,si1 st1 機器上分別導入 install.sql 并 pt-query-digest 慢日志進去
-rwxrwxrwx 1 root root 0 Oct 13 2016 index.html
-rwxrwxrwx 1 root root 15487 Oct 13 2016 sample.config.inc.php
[root@RZ-SI1-DB-14 conf]# more datasource_si1.inc.php
?php
$conf[datasources][si1] = array(
host = 10.38.96.132 ,
port = 3306,
db = slow_query_log ,
user = xxxxxx ,
password = xxxxxx ,
tables = array(
global_query_review = fact ,
global_query_review_history = dimension
),
source_type = slow_query_log
);
[root@RZ-SI1-DB-14 conf]# more datasource_st1.inc.php
?php
$conf[datasources][st1] = array(
host = 10.38.96.128 ,
port = 3306,
db = slow_query_log ,
user = xxxxxxx ,
password = xxxxxxxx ,
tables = array(
global_query_review = fact ,
global_query_review_history = dimension
),
source_type = slow_query_log
);
感謝各位的閱讀!關于“Mysql 中 Anemometer 怎么用”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!