Objective
Using anemometer to visualize the MySQL slow query log, you can more easily query the slow query log, and based on the time stamp of historical query. The following is a stand-alone version of the Anemometer deployment demonstration, in practice, for security reasons, it is recommended to separate the anemometer to another machine.
Working principle
Anemometer: Implementing Log Visualization
Pt-query-digest: Extracting slow query log
Environmental information
Ip |
Function |
Software information |
Installation path |
Operating system |
192.168.9.11 |
HTTP Service |
httpd-2.2.15-54 |
Yum Default Path |
centos6.9 |
Slow query log Fetch import |
Pt-query-digest |
RPM Default Path |
Slow query Log Cutting |
Logrotate |
Yum Default Path |
Visual display |
Anemometer |
/var/www/html |
Installation steps
1. Installing Apache
Yum Install Httpd-y
2. Install the pt-query-digest and set up the crawl script
Yum install perl-dbi perl-dbd-mysql perl-time-hires Perl-io-socket-ssl-y# need to install Perl-Termreadkey Otherwise will error wget http://pkgs.repoforge.org/perl-termreadkey/perl-termreadkey-2.30-1.el3.rf.x86_64.rpmRPM-IVH perl-termreadkey-2.30-1. El3.rf.x86_64.rpmwget https://www.percona.com/downloads/percona-toolkit/2.2.20/RPM/percona-toolkit-2.2.20-1.noarch.rpmRPM-IVH percona-toolkit-2.2. --1. Noarch.rpmvim/home/shell_script/slow_db_export.sh#!/bin/Bash/usr/bin/pt-query-digest--user=anemometer--password=123456--review h=192.168.9.11, D=slow_query_log,t=global_query_review--history h=192.168.9.11, D=slow_query_log,t=global_query_review_history--no-report--limit=0%--filter="\ $event->{bytes} = Length (\ $event->{arg}) and \ $event->{hostname}=\ "$HOSTNAME \""/usr/local/mysql/data/Mysql.slowchmod-R755/home/shell_script/slow_db_export.sh
3. Install the logrotate and configure the daily cut MySQL slow query log
Yum Install logrotate-Yvim/etc/logrotate.d/MySQL/usr/local/mysql/data/Mysql.slow {Create660MySQL mysqldateextnotifemptydailymaxage -Rotate -Missingokcompressolddir/usr/local/mysql/old_logpostrotate######### #runifMysqld isRunningif/usr/local/mysql/bin/mysqladmin ping-h172.27.127. A-uroot-p'hs!hs8989'-s/usr/local/mysql/mysql.sock &>/dev/NULL; Then/usr/local/mysql/bin/mysqladmin flush-logs-h172.27.127. A-uroot-p'hs!hs8989'-s/usr/local/mysql/Mysql.sockfiendscript}chmod-R755/etc/logrotate.d/mysql
4. Put the Pt-query-digest script and the logrotate cut script into the crontab
############ #23点55分- slow query data for split import day ##################### * * * /home/shell_script /slow_db_export.sh############## #23点59分- cut slow query log ############# * * * Root (/ Usr/sbin/logrotate-f/etc/logrotate.d/mysql)
5. Installing anemometer
cd/var/www/htmlgit clone https: // Span style= "COLOR: #008000" >github.com/box/anemometer.git anemometer&&cd anemometer #创建表和用户名 # mysql -uroot-proot < install.sql# MySQL - UROOT-PROOT-E " grant all on slow_query_log.* to ' Anemometer ' @ ' localhost ' identified by ' 123456 '; " # mysql -uroot-proot-e " grant Select On * * to ' anemometer ' @ ' localhost ' identified by ' 123456 '; " # mysql -uroot-proot-e " flush privileges; "
6. Import the log and open the page test (http://192.168.9.11/amemometer
#执行刚刚编辑的slow_db_export. sh script./home/shell_script/slow_db_export.sh# Restart Apacheservice httpd restart
At this point, the MySQL slow query log visualization function has been realized through anemometer.
10-minute deployment of anemometer as a MySQL slow query visualization system