赞
踩
MySQL数据库是轻量级、开源数据库的佼佼者,其功能和管理,健壮性与Oracle相比还是有相当的差距。因此有很多功能强大第三方的衍生产品,如percona-toolkit,XtraBackup等等。percona-toolkit是一组高级命令行工具的集合,可以查看当前服务的摘要信息,磁盘检测,分析慢查询日志,查找重复索引,实现表同步等等。这个工具套件对DBA及运维人员着实不可多得。本文简要描述这个工具的安装及其工具的大致介绍。
实验环境:OS: CentOS Linux release 7.4.1708 (Core);Mysql:5.7.22。
Ptheartbeat1: 192.168.43.219
Ptheartbeat2: 192.168.43.128
Verify MySQL replication integrity by checking master and replica data consistency
Efficiently archive rows
Find duplicate indexes
Summarize MySQL servers
Analyze queries from logs and tcpdump
Collect vital system information when problems occur
其中要创建test库,以便创建心跳表:create database test;
下载链接:http://www.percona.com/software/percona-toolkit
需求
* Perl v5.8 or newer
* Bash v3 or newer
* Core Perl modules like Time::HiRes
版本检查
# perl --version |head -2 #检查perl版本
# bash --version #检查bash版本
快速安装步骤(缺省/usr/local/bin路径下,过程略)
# tar zxvf percona-toolkit-3.0.13_x86_64.tar.gz
# cd /root/percona-toolkit-3.0.13
# perl Makefile.PL (安装到非缺省目录 perl Makefile.PL PREFIX=${HOME})
报错1:Can't locate ExtUtils/MakeMaker.pm in @INC
解决1:yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
报错2 [root@master percona-toolkit-3.0.13]# perl Makefile.PL
Checking if your kit is complete...
Looks good
Warning: prerequisite DBD::mysql 3 not found.
Writing Makefile for percona-toolkit
我忽略了如上报错。
解决2:yum install perl-DBD-MySQL(需要安装rpm -ivh mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm)否则报错
Error: Package: perl-DBD-MySQL-4.023-6.el7.x86_64 (base)
Requires: libmysqlclient.so.18()(64bit)
Error: Package: perl-DBD-MySQL-4.023-6.el7.x86_64 (base)
Requires: libmysqlclient.so.18(libmysqlclient_18)(64bit)
rpm -ivh perl-DBD-MySQL-4.023-6.el7.x86_64.rpm(网上下载的包)
[root@master percona-toolkit-3.0.13]# perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for percona-toolkit
# make
# make test
[root@master percona-toolkit-3.0.13]# make test
No tests defined for percona-toolkit extension.
附:出现上面这个不是问题,继续安装
# make install
[root@DBMASTER01 ~]# pt-heartbeat --user=root --password=Qaz123$%^ -D test --master-server-id=219 --create-table --update
上述语句在执行时,可能会卡住,不过没关系,表已经创建成功。
MASTER> select * from heartbeat;
mysql> select * from heartbeat;
+----------------------------+-----------+------------------+----------+-----------------------+---------------------+
| ts | server_id | file | position | relay_master_log_file | exec_master_log_pos |
+----------------------------+-----------+------------------+----------+-----------------------+---------------------+
| 2019-10-14T14:32:39.002530 | 219 | mysql-bin.000001 | 364804 | NULL | NULL |
+----------------------------+-----------+------------------+----------+-----------------------+---------------------+
1 row in set (0.00 sec)
[root@DBMASTER01 ~]# pt-heartbeat --user=root --password=Qaz123$%^ -D test --master-server-id=219 --update &
[1] 31249
[root@master lib]# pt-heartbeat --user=root --password=Qaz123$%^ -D test --master-server-id=219 --monitor --print-master-server-id
0.00s [ 0.00s, 0.00s, 0.00s ] 219 #实时延迟,1分钟延迟,5分钟延迟,15分钟延迟
0.00s [ 0.00s, 0.00s, 0.00s ] 219
0.00s [ 0.00s, 0.00s, 0.00s ] 219
0.00s [ 0.00s, 0.00s, 0.00s ] 219
0.00s [ 0.00s, 0.00s, 0.00s ] 219
0.00s [ 0.00s, 0.00s, 0.00s ] 219
[root@master ~]# pt-heartbeat --user=root --password=Qaz123$%^ -D test --master-server-id=219 --update --daemonize
#修改主库上的更新间隔为2s(发现先停掉主库守护进行,删除哨兵文件,执行下面命令,才能改为2秒)
[root@DBMASTER01 ~]# pt-heartbeat --user=root --password=Qaz123$%^ -D test --master-server-id=219 --update --daemonize --interval=2
#停止主库上的pt-heartbeat守护进程
[root@DBMASTER01 ~]# pt-heartbeat --stop
Successfully created file /tmp/pt-heartbeat-sentinel
[root@DBMASTER01 ~]# rm -rf /tmp/pt-heartbeat-sentinel
[root@master lib]# pt-heartbeat --user=root --password=Qaz123$%^ -D test --master-server-id=219 --check
1.00
pt-heartbeat --user=root --password=Qaz123$%^ -D test --master-server-id=219 --monitor --print-master-server-id --daemonize --log=/root/slave-lag.log
通过如下命令查看日志:
[root@master ~]# tail -200f /root/slave-lag.log
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。