使用Anemometer基于pt-query-digest将MySQL慢查询可视化

=============

欢迎转载,请注明出处

作者:李慧 (DBA)

日期:20151008

=============

1 安装Percona Toolkit

  去官网下载

2. 安装Anemometer

下载地址:https://github.com/box/Anemometer

3.下载PHP 相关模块

 yum -y install php*

主要看这些模块:

php-common-5.3.3-1.el5
php-bcmath-5.3.3-1.el5
php-mysql-5.3.3-1.el5
php-dba-5.3.3-1.el5
php-cli-5.3.3-1.el5
php-gd-5.3.3-1.el5
php-5.3.3-1.el5
php-pdo-5.3.3-1.el5

4.启动apache服务
rpm -qa|grep http
httpd-2.2.3-45.el5

 

5..执行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 '123456';

mysql > grant all on slow_query_log.* to 'anemometer'@'localhost' identified by '123456';

mysql > grant select on *.* to  'anemometer'@'%';
mysql > grant all on slow_query_log.* to 'anemometer'@'localhost';
mysql > grant select on *.* to  'anemometer'@'localhost';

 

6.修改PHP配置文件:

vim /etc/php.ini

 

7.修改WEB页面:

cd /var/www/html/anemometer/conf
cp sample.config.inc.php config.inc.php
vi config.inc.php

 

以及

 

 

8. 修改APACHE配置文件“

cat /etc/httpd/conf/httpd.conf |grep "ServerName" |grep -v '^#'
ServerName 10.1.11.99:80

 

重启HTTP,访问不了,报错如下:

tail -f /etc/httpd/logs/error_log

 

解决方法如下:

 

 

 

9:访问页面:

10.1.11.99/anemometer

 

 11.导入慢查询日志

 pt-query-digest --user=anemometer --password=123456 --socket=/tmp/mysql3306.sock  --review h=localhost,D=slow_query_log,t=global_query_review  --history h=localhost,D=slow_query_log,t=global_query_review_history  --no-report --limit=0% --filter=" \$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"$HOSTNAME\"" /opt/soft/slow_query_2015-09-24.log

 

 

参考:http://www.bubuko.com/infodetail-495427.html

https://github.com/box/Anemometer

http://blog.itpub.net/26355921/viewspace-1162415/

 

posted @ 2015-10-08 14:24  lihbeibei  阅读(370)  评论(0编辑  收藏  举报