标签:disk plain fas 命令行 可视化工具 server lamp环境 limit error
Anemometer可以把MySQL慢查询可视化,方便我们去找出和分析慢询语句.anemometer基于Percona Toolkit
Percona Toolkit是一组高级的命令行工具,用来管理 MySQL 和系统任务,主要包括:
1、验证主节点和复制数据的一致性
2、有效的对记录行进行归档
3、找出重复的索引
4、总结 MySQL 服务器
5、从日志和 tcpdump 中分析查询
6、问题发生时收集重要的系统信息
~]$ sudo yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
~]$ sudo yum install percona-toolkit
~]$ sudo rpm -ql percona-toolkit //
/usr/bin/pt-align
/usr/bin/pt-archiver
/usr/bin/pt-config-diff
/usr/bin/pt-deadlock-logger
/usr/bin/pt-diskstats
/usr/bin/pt-duplicate-key-checker
/usr/bin/pt-fifo-split
/usr/bin/pt-find
/usr/bin/pt-fingerprint
/usr/bin/pt-fk-error-logger
/usr/bin/pt-heartbeat
/usr/bin/pt-index-usage
/usr/bin/pt-ioprofile
/usr/bin/pt-kill
/usr/bin/pt-mext
/usr/bin/pt-mongodb-query-digest
/usr/bin/pt-mongodb-summary
/usr/bin/pt-mysql-summary
/usr/bin/pt-online-schema-change
/usr/bin/pt-pmp
/usr/bin/pt-query-digest
/usr/bin/pt-show-grants
/usr/bin/pt-sift
/usr/bin/pt-slave-delay
/usr/bin/pt-slave-find
/usr/bin/pt-slave-restart
/usr/bin/pt-stalk
/usr/bin/pt-summary
/usr/bin/pt-table-checksum
/usr/bin/pt-table-sync
/usr/bin/pt-table-usage
/usr/bin/pt-upgrade
/usr/bin/pt-variable-advisor
/usr/bin/pt-visual-explain
github: https://github.com/box/Anemometer
安装好lnmp或lamp环境
~]$ git clone git://github.com/box/Anemometer.git
~]$ sudo mv anemometer/ /var/www/
~]$ sudo mysql -uroot -pAa123456 < /var/www/anemometer/mysql56-install.sql
> grant all on slow_query_log.* to 'anemometer'@'%' identified by 'anem**0815';
> grant all on slow_query_log.* to 'anemometer'@'localhost' identified by 'anem**0815';
> grant select on *.* to 'anemometer'@'%';
> grant select on *.* to 'anemometer'@'localhost';
> flush privileges;
~]$ cd /var/www/anemometer/conf/
conf]$ cp sample.config.inc.php config.inc.php
conf]$ vim config.inc.php
'explain' => function ($sample) {
.......
.....
$conn['user'] = 'anemometer';
$conn['password'] = 'anem**0815';
~]$ sudo vim /var/www/anemometer/conf/datasource_localhost.inc.php
$conf['datasources']['localhost'] = array(
'host' => 'localhost',
'port' => 3306,
'db' => 'slow_query_log',
'user' => 'anemometer',
'password' => 'anem**0815',
配置
~]$ sudo vim /etc/nginx/conf.d/Anemometer.conf
server {
listen 80;
server_name explain.aa.com;
index index.htm index.html index.php;
root /var/www/anemometer;
location ~ \.php$ {
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
}
access_log /var/log/nginx/anem.log main;
error_log /var/log/nginx/anem_error.log;
}
服务重启
~]$ sudo nginx -s reload
~]$ sudo chown -R nginx.nginx /var/www/
访问
http://explain.aa.com/
Table 'slow_query_log.global_query_review' doesn't exist (1146) # 错误提示
前面说了这可视化工具基于percona-toolkit,现在我们还没用上这工具呢
~]$ sudo pt-query-digest --user=anemometer --password=anem**0815 --socket=/var/lib/mysql/mysql.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\"" /var/lib/mysql/mysql-slow.log
*******************************************************************
at /bin/pt-query-digest line 11914.
/var/lib/mysql/mysql-slow.log: 0% 01:11:07 remain
/var/lib/mysql/mysql-slow.log: 1% 01:10:33 remain
/var/lib/mysql/mysql-slow.log: 2% 01:09:39 remain
/var/lib/mysql/mysql-slow.log: 2% 01:09:04 remain
/var/lib/mysql/mysql-slow.log: 3% 01:08:32 remain
/var/lib/mysql/mysql-slow.log: 4% 01:08:15 remain # 导入过程比较慢
将其它数据库服务器上的慢查询日志拉取到本地进行分析
标签:disk plain fas 命令行 可视化工具 server lamp环境 limit error
原文地址:https://www.cnblogs.com/knmax/p/12150357.html