https://www.percona.com/doc/percona-repo-config/yum-repo.htmlhtml
sudo yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
[root@node1 ~]# sudo yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm Loaded plugins: fastestmirror percona-release-0.1-4.noarch.rpm | 6.4 kB 00:00:00 Examining /var/tmp/yum-root-NKCxiN/percona-release-0.1-4.noarch.rpm: percona-release-0.1-4.noarch Marking /var/tmp/yum-root-NKCxiN/percona-release-0.1-4.noarch.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package percona-release.noarch 0:0.1-4 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================= Package Arch Version Repository Size ============================================================================================= Installing: percona-release noarch 0.1-4 /percona-release-0.1-4.noarch 5.8 k Transaction Summary ============================================================================================= Install 1 Package Total size: 5.8 k Installed size: 5.8 k Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : percona-release-0.1-4.noarch 1/1 Verifying : percona-release-0.1-4.noarch 1/1 Installed: percona-release.noarch 0:0.1-4 Complete!
sudo yum list | grep percona-toolkit
percona-toolkit.noarch 2.2.20-1 percona-release-noarch percona-toolkit.x86_64 3.0.9-1.el7 percona-release-x86_64 percona-toolkit-debuginfo.x86_64 3.0.9-1.el7 percona-release-x86_64
sudo yum install percona-toolkit
Installed: percona-toolkit.x86_64 0:3.0.9-1.el7 Dependency Installed: perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBD-MySQL.x86_64 0:4.023-5.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-Digest.noarch 0:1.17-245.el7 perl-Digest-MD5.x86_64 0:2.52-3.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-IO-Socket-IP.noarch 0:0.21-4.el7 perl-IO-Socket-SSL.noarch 0:1.94-6.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-Net-LibIDN.x86_64 0:0.12-15.el7 perl-Net-SSLeay.x86_64 0:1.55-6.el7 perl-PlRPC.noarch 0:0.2020-14.el7 Complete!
工具類別
|
工具命令
|
工具做用
|
備註
|
開發類
|
pt-duplicate-key-checker
|
列出並刪除重複的索引和外鍵
|
|
pt-online-schema-change
|
在線修改表結構
|
|
|
pt-query-advisor
|
分析查詢語句,並給出建議,有bug
|
已廢棄
|
|
pt-show-grants
|
規範化和打印權限
|
|
|
pt-upgrade
|
在多個服務器上執行查詢,並比較不一樣
|
|
|
性能類
|
pt-index-usage
|
分析日誌中索引使用狀況,並出報告
|
|
pt-pmp
|
爲查詢結果跟蹤,並彙總跟蹤結果
|
|
|
pt-visual-explain
|
格式化執行計劃
|
|
|
pt-table-usage
|
分析日誌中查詢並分析表使用狀況
|
pt 2.2新增命令
|
|
配置類
|
pt-config-diff
|
比較配置文件和參數
|
|
pt-mysql-summary
|
對mysql配置和status進行彙總
|
|
|
pt-variable-advisor
|
分析參數,並提出建議
|
|
|
監控類
|
pt-deadlock-logger
|
提取和記錄mysql死鎖信息
|
|
pt-fk-error-logger
|
提取和記錄外鍵信息
|
|
|
pt-mext
|
並行查看status樣本信息
|
|
|
pt-query-digest
|
分析查詢日誌,併產生報告
|
經常使用命令
|
|
pt-trend
|
按照時間段讀取slow日誌信息
|
已廢棄
|
|
複製類
|
pt-heartbeat
|
監控mysql複製延遲
|
|
pt-slave-delay
|
設定從落後主的時間
|
|
|
pt-slave-find
|
查找和打印全部mysql複製層級關係
|
|
|
pt-slave-restart
|
監控salve錯誤,並嘗試重啓salve
|
|
|
pt-table-checksum
|
校驗主從複製一致性
|
|
|
pt-table-sync
|
高效同步表數據
|
|
|
系統類
|
pt-diskstats
|
查看系統磁盤狀態
|
|
pt-fifo-split
|
模擬切割文件並輸出
|
|
|
pt-summary
|
收集和顯示系統概況
|
|
|
pt-stalk
|
出現問題時,收集診斷數據
|
|
|
pt-sift
|
瀏覽由pt-stalk建立的文件
|
pt 2.2新增命令
|
|
pt-ioprofile
|
查詢進程IO並打印一個IO活動表
|
pt 2.2新增命令
|
|
實用類
|
pt-archiver
|
將表數據歸檔到另外一個表或文件中
|
|
pt-find
|
查找表並執行命令
|
|
|
pt-kill
|
Kill掉符合條件的sql
|
經常使用命令
|
|
pt-align
|
對齊其餘工具的輸出
|
pt 2.2新增命令
|
|
pt-fingerprint
|
將查詢轉成密文
|
pt 2.2新增命令
|
1\. 鏈接到主庫:pt工具鏈接到主庫,而後自動發現主庫的全部從庫。默認採用show full processlist來查找從庫,可是這隻有在主從實例端口相同的狀況下才有效。3\. 查找主庫或者從庫是否有複製過濾規則:這是爲了安全而默認檢查的選項。你能夠關閉這個檢查,可是這可能致使checksum的sql語句要麼不會同步到從庫,要麼到了從庫發現從庫沒有要被checksum的表,這都會致使從庫同步卡庫。5\. 開始獲取表,一個個的計算。6\. 若是是表的第一個chunk,那麼chunk-size通常爲1000;若是不是表的第一個chunk,那麼採用19步中分析出的結果。7\. 檢查表結構,進行數據類型轉換等,生成checksum的sql語句。8\. 根據表上的索引和數據的分佈,選擇最合適的split表的方法。9\. 開始checksum表。10\. 默認在chunk一個表以前,先刪除上次這個表相關的計算結果。除非–resume。14\. 根據explain的結果,判斷chunk的size是否超過了你定義的chunk-size的上限。若是超過了,爲了避免影響線上性能,這個chunk將被忽略。15\. 把要checksum的行加上for update鎖,並計算。17-18\. 把計算結果存儲到master_crc master_count列中。19\. 調整下一個chunk的大小。20\. 等待從庫追上主庫。若是沒有延遲備份的從庫在運行,最好檢查全部的從庫,若是發現延遲最大的從庫延遲超過max-lag秒,pt工具在這裏將暫停。21\. 若是發現主庫的max-load超過某個閾值,pt工具在這裏將暫停。22\. 繼續下一個chunk,直到這個table被chunk完畢。23-24\. 等待從庫執行完checksum,便於生成彙總的統計結果。每一個表彙總並統計一次。25-26\. 循環每一個表,直到結束。
select * from percona.checksums where master_cnt <> this_cnt OR master_crc <> this_crc OR ISNULL(master_crc) <> ISNULL(this_crc) \G
CREATE DATABASE IF NOT EXISTS percona; CREATE TABLE IF NOT EXISTS percona.checksums ( db CHAR(64) NOT NULL, tbl CHAR(64) NOT NULL, chunk INT NOT NULL, chunk_time FLOAT NULL, chunk_index VARCHAR(200) NULL, lower_boundary TEXT NULL, upper_boundary TEXT NULL, this_crc CHAR(40) NOT NULL, this_cnt INT NOT NULL, master_crc CHAR(40) NULL, master_cnt INT NULL, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (db,tbl,chunk), INDEX ts_db_tbl(ts,db,tbl) ) ENGINE=InnoDB;
create database school; use school;
CREATE TABLE `students` ( `SID` tinyint(4) NOT NULL AUTO_INCREMENT, `Name` varchar(50) NOT NULL, `Age` tinyint(4) NOT NULL, `Gender` enum('M','F') NOT NULL, `Mobile` char(11) NOT NULL, `Address` varchar(255) DEFAULT NULL, PRIMARY KEY (`SID`), UNIQUE KEY `Name` (`Name`), UNIQUE KEY `Name_2` (`Name`), UNIQUE KEY `index_name` (`Name`), KEY `Mobile` (`Mobile`) ) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=latin1;
INSERT INTO students (Name, Age, Gender, Mobile, Address) VALUES ('w1',41,'F',1111111,'doagnagv'); INSERT INTO students (Name, Age, Gender, Mobile, Address) VALUES ('w2',42,'F',2222222,'dagongws'); INSERT INTO students (Name, Age, Gender, Mobile, Address) VALUES ('w3',43,'F',3333333,'doagdnga'); INSERT INTO students (Name, Age, Gender, Mobile, Address) VALUES ('w4',44,'F',4444444,'dvzxonga'); INSERT INTO students (Name, Age, Gender, Mobile, Address) VALUES ('w5',45,'F',5555555,'dozgngas'); INSERT INTO students (Name, Age, Gender, Mobile, Address) VALUES ('w6',46,'F',6666666,'dagongzg'); INSERT INTO students (Name, Age, Gender, Mobile, Address) VALUES ('w7',47,'F',7777777,'vsdgdong'); INSERT INTO students (Name, Age, Gender, Mobile, Address) VALUES ('w8',48,'F',8888888,'vsdgdong'); INSERT INTO students (Name, Age, Gender, Mobile, Address) VALUES ('w9',49,'F',9999999,'vsgagaga');
UPDATE students SET age = 43 WHERE Name = 'w3';
DELETE FROM students WHERE Name = 'w4';
開始實驗能夠看到主從是正常的狀態node
如今開始搞事情,將從庫的一條數據刪除:mysql
[root@node1 ~]# pt-table-checksum h='192.168.112.128',u='root',p='123456',P=3306 -d school --recursion-method=processlist --nocheck-replication-filters --replicate=percona.checksums --no-check-binlog-format --ignore-databases=mysql --engines=innodb Checking if all tables can be checksummed ... Starting checksum ... TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE 05-08T14:26:45 0 0 9 1 0 0.030 school.students
" The number of chunks that differ from the master on one or more replicas. If --no-replicate-check is specified, this column will always have zeros. If --replicate-check-only is specified, then only tables with differences are printed."
[root@node1 ~]# pt-table-sync --print --sync-to-master h=192.168.112.131,u=root,p='123456',P=3306 --verbose --wait=10 --transaction --engines=innodb -d school --tables=students --recursion-method=processlist --check-triggers --foreign-key-checks -unique-checks --charset=utf8mb4
【ERROR】1032:刪除或更新數據,從庫找不到記錄sql
mysql> stop slave; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000017', MASTER_LOG_POS=62376; Query OK, 0 rows affected (0.01 sec) mysql> start slave; Query OK, 0 rows affected (0.00 sec)
mysql> stop slave; mysql> set global sql_slave_skip_counter=1; mysql> start slave;
主從又出現了這個問題mongodb
mysql> show binlog events in 'mysql-bin.000017' from 62696 limit 10; +------------------+-------+------------+-----------+-------------+-----------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +------------------+-------+------------+-----------+-------------+-----------------------+ | mysql-bin.000017 | 62696 | Xid | 1 | 62727 | COMMIT /* xid=3230 */ | +------------------+-------+------------+-----------+-------------+-----------------------+ 1 row in set (0.00 sec)
[root@node1 lyj]# pt-table-checksum h='192.168.112.128',u='root',p='123456',P=3306 -d schooursion-method=processlist --nocheck-replication-filters --replicate=percona.checksums --no-inlog-format --ignore-databases=mysql --engines=innodb Checking if all tables can be checksummed ... Starting checksum ... TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE 05-08T15:06:11 0 0 9 1 0 0.021 school.students [root@node1 lyj]# pt-table-sync --execute --sync-to-master h=192.168.112.131,u=root,p='123456',P=3306 --verbose --wait=10 --transaction --engines=innodb -d school --tables=students --recursion-method=processlist --check-triggers --foreign-key-checks -unique-checks --charset=utf8mb4 # Syncing A=utf8mb4,P=3306,h=192.168.112.131,p=...,u=root # DELETE REPLACE INSERT UPDATE ALGORITHM START END EXIT DATABASE.TABLE # 0 1 0 0 Chunk 15:06:23 15:06:23 2 school.students