Installation PERCONA-TOOLKIT

1. Based on MySQL master-slave environment

Can refer https://www.cnblogs.com/tyk3201/p/12054586.html

Upload and install rpm package

1
2
cd /usr/local/src
yum -y install percona-toolkit-3.1.0-2.el7.x86_64.rpm 

Create a table in a sbtest (there is the premise of stone) database table called heartbeat

1
pt-heartbeat -S /var/lib/mysql/mysql .sock --database sbtest --update --create-table --daemonize   

Download pressure measurement tool

1
2
yum -y install epel*
yum -y kainstall sysbench   

Pressure began to implement experimental measurement of sbtest database

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   // 开始压测测试  

Pressure began to really test

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   // 开始压测实战  

Performed on the virtual discipline from the beginning really in pressure measured when the next command to the virtual machine and the main database simultaneously executed

1
pt-heartbeat -S /var/lib/mysql/mysql .sock --master-server- id =1 --monitor --database sbtest  

Garbage generated data recovery

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   // 回收垃圾信息 

 We are just running in the background

1
2
ps aux | grep perl
pt-heartbeat /usr/bin/pt-heartbeat -S /var/lib/mysql/mysql .sock --database sbtest --update --create-table --stop  // 关掉进程

 test database in the master database to create a table named z1 of

1
2
use test ;
  create table z1 ( id int not null, name varchar(32), primary key( id ));

 Data from the

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)

 Back insert data on the primary

1
2
insert into z1( id ,name) values(2, "mysql" );
insert into z1( id ,name) values(3, "python" );

  View from the slave back to the state there have been mistakes

  

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

  

Detecting data consistency from the command master

On the primary database

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 TABLE
12-17T11:47:14      0      0        2          0       1       0   0.011 test .z1  

 Never repair the master synchronization

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  // 校验

  

Guess you like

Origin www.cnblogs.com/tyk3201/p/12054593.html
Recommended