这篇文章给大家分享的是有关Mysql中Anemometer怎么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
准备条件:
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怎么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!