percona-toolkit工具的安装
yum install -y perl-DBI
yum install -y perl-DBD-MySQL
yum install -y perl-Time-HiRes
yum install -y perl-IO-Socket-SSL
yum install -y perl-TermReadKey
yum install -y perl-Digest-MD5
rpm包下载地址:
www.percona.com/downloads/percona-toolkit
rpm -ivh percona-toolkit-3.0.13-1.el7.x86_64.rpm
检查是否安装成功:
pt-query-digest --version
php web环境的搭建
安装目的:Anemometer需要依赖LAMP环境
LAMP环境的安装:
安装apache
yum install httpd httpd-devel -y
安装php
yum install php php-mysql php-common php-bcmath php-dba php-cli php-gd php-mbstring php-mcrypt php-devel php-xml php-pdo -y
修改时区,
vim /etc/php.ini
修改为 date.timezone = "Asia/Shanghai"
LAMP环境的启动
systemctl start httpd
安装Anemometer并配置
下载地址:https://github.com/box/Anemometer
移动到对应路径:mv Anemometer/* /var/www/html/
目标慢查询数据库上需要授予Anemometer主机对应的权限
grant select on *.* to 'anemometer'@'%' identified by 'chengce243';
flush privileges;
修改配置文件增加explain读取用户密码信息
cp conf/sample.config.inc.php conf/config.inc.php
vim conf/config.inc.php
修改两处地方:
1.
$conf['datasources']['172.16.0.128'] = array(
'host' => '172.16.0.128',
'port' => 3306,
'db' => 'slow_query_log',
'user' => 'root',
'password' => 'chengce243',
'tables' => array(
'events_statements_summary_by_digest' => 'fact',
),
'source_type' => 'slow_query_log'
);
2.
$conn['user'] = 'root';
$conn['password'] = 'chengce243';
vim conf/datasource_localhost.inc.php
<?php
$conf['datasources']['172.16.0.128'] = array(
'host' => '172.16.0.128',
'port' => 3306,
'db' => 'slow_query_log',
'user' => 'root',
'password' => 'chengce243',
'tables' => array(
'global_query_review' => 'fact',
'global_query_review_history' => 'dimension'
),
'source_type' => 'slow_query_log'
);
初始化数据源的数据库表的配置
mysql -uroot -pchengce243 -h127.0.0.1 < mysql56-install.sql
导入慢查询日志
$ pt-query-digest --user=anemometer --password=superSecurePass
--review h=db.example.com,D=slow_query_log,t=global_query_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""
/var/lib/mysql/db.example.com-slow.log
打开网站:
http://172.16.0.128/anemometer