PERCONA-TOOLKIT 安装 使用
1.基于MySQL主从环境
可以参考https://www.cnblogs.com/tyk3201/p/12054586.html
上传rpm包 并安装
|
1
2
|
cd /usr/local/srcyum -y install percona-toolkit-3.1.0-2.el7.x86_64.rpm |
在一个sbtest(前提石存在)的数据库中创建一个表叫heartbeat的表
|
1
|
pt-heartbeat -S /var/lib/mysql/mysql.sock --database sbtest --update --create-table --daemonize |
下载压测工具
|
1
2
|
yum -y install epel*yum -y kainstall sysbench |
开始实行压测对sbtest数据库 实验
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
sysbench /usr/share/sysbench/oltp_read_write.lua \> --mysql-host='192.168.18.140' \ //主的数据库的IP地址> --mysql-user=sbtest \ //用户> --mysql-password=123456 \ //用户密码> --mysql-port=3306 \ //主数据库的端口> --db-driver=mysql \ //数据库的类型> --mysql-db=sbtest \ //要进行压测的数据库> --tables=10 \ //要创建10张表> --table-size=500000 \ //每一张数据表中的插入50万条数据> --report-interval=10 \ //报告间隔> --threads=128 \ //开启128个线程> --time=120 \ //执行两分钟> prepare //开始压测测试 |
开始真的压测
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
sysbench /usr/share/sysbench/oltp_read_write.lua \> --mysql-host='192.168.18.140' \ //主的数据库的IP地址> --mysql-user=sbtest \ //用户> --mysql-password=123456 \ //用户密码> --mysql-port=3306 \ //主数据库的端口> --db-driver=mysql \ //数据库的类型> --mysql-db=sbtest \ //要进行压测的数据库> --tables=10 \ //要创建10张表> --table-size=500000 \ //每一张数据表中的插入50万条数据> --report-interval=10 \ //报告间隔> --threads=128 \ //开启128个线程> --time=120 \ //执行两分钟> run //开始压测实战 |
在开始真的压测的时候 在从的的虚拟纪上执行下一条命令要和主的数据库的虚拟机同时执行
|
1
|
pt-heartbeat -S /var/lib/mysql/mysql.sock --master-server-id=1 --monitor --database sbtest |
将产生的垃圾数据回收
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
sysbench /usr/share/sysbench/oltp_read_write.lua \> --mysql-host='192.168.18.140' \ //主的数据库的IP地址> --mysql-user=sbtest \ //用户> --mysql-password=123456 \ //用户密码> --mysql-port=3306 \ //主数据库的端口> --db-driver=mysql \ //数据库的类型> --mysql-db=sbtest \ //要进行压测的数据库> --tables=10 \ //要创建10张表> --table-size=500000 \ //每一张数据表中的插入50万条数据> --report-interval=10 \ //报告间隔> --threads=128 \ //开启128个线程> --time=120 \ //执行两分钟> cleanup //回收垃圾信息 |
刚刚我们是在后台运行
|
1
2
|
ps aux | grep perlpt-heartbeat /usr/bin/pt-heartbeat -S /var/lib/mysql/mysql.sock --database sbtest --update --create-table --stop //关掉进程 |
在主的数据库中的test数据库创建一个名叫z1的表
|
1
2
|
use test; create table z1 ( id int not null, name varchar(32), primary key(id)); |
在从的数据
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
use test;MariaDB [test]> select * from z1;Empty set (0.00 sec)MariaDB [test]> set sql_log_bin=0;Query OK, 0 rows affected (0.00 sec)MariaDB [test]> set global read_only=off;Query OK, 0 rows affected (0.01 sec)MariaDB [test]> insert into z1(id,name) values(3,"python");Query OK, 1 row affected (0.00 sec)MariaDB [test]> select * from z1;+----+--------+| id | name |+----+--------+| 3 | python |+----+--------+1 row in set (0.00 sec) |
回到主上 插入数据
|
1
2
|
insert into z1(id,name) values(2,"mysql");insert into z1(id,name) values(3,"python"); |
回到从上 查看slave的状态 会有错误
|
1
2
3
4
5
6
7
8
9
10
|
show slave status \G;有一个类似这样的错误 Last_Errno: 1062 Last_Error: Error 'Duplicate entry '3' for key 'PRIMARY'' on query. Default database: 'test'. Query: 'insert into z1(id,name) values(3,"python")'在执行一条命令pt-slave-restart --error-numbers=1062 //跳过错误再去查看一下slave的状态 就可以看到双yes |
检测主从数据一致性的命令
在主的数据库上
|
1
2
3
4
5
6
7
|
pt-table-checksum --nocheck-replication-filters --no-check-binlog-format --replicate=test.checksums --create-replicate-table --databases=test --tables=z1 h=192.168.18.140,u=sbtest,p=123456,P=3306//执行效果 说的是检测到一条没有同步Checking if all tables can be checksummed ...Starting checksum ... TS ERRORS DIFFS ROWS DIFF_ROWS CHUNKS SKIPPED TIME TABLE12-17T11:47:14 0 0 2 0 1 0 0.011 test.z1 |
修复主从不同步
|
1
2
3
|
pt-table-sync --replicate=test.checksums h=172.18.47.110,u=huazai007,p=123456,P=3306 h=172.18.47.112,u=huazai007,p=123456,P=3306 --print 只是打印pt-table-sync --replicate=test.checksums h=172.18.47.110,u=huazai007,p=123456,P=3306 h=172.18.47.112,u=huazai007,p=123456,P=3306 --execute //校验 |
浙公网安备 33010602011771号