MySQL深度巡檢


1. IO層面檢查

 
(1) IO檢查
 

查看%util是否接近100%定位是哪個磁盤IO壓力大

#iostat -x 1 10
(2) iotop定位負載來源進程
查看哪個PID占用IO最高
#iotop
(3) pt-ioprofile定位負載來源文件
查看哪個文件的IO占用時間最多
#pt-ioprofile  --profile-pid=3712 --cell=sizes
 
 
2.文件系統層面檢查
(1)查看當前系統的 I/O調度
假如MySQL數據文件存放在sda1里,不同的磁盤則選擇不同的IO調度策略

# cat /sys/block/sda/queue/scheduler

(2)查看文件系統
查看MySQL數據文件存放的文件系統是否為xfs或者ext4
#mount
 
3.linux內核參數檢查

# cat /etc/sysctl.cnf

 

4.收集MySQL數據庫基本信息

(1)收集OS基本信息

#pt-summary

(2)查看MySQL統計信息

#pt-mysql-summary --user=root --password=123456 --host=127.0.0.1 --port=3306

(3)查看用戶數據庫的存儲引擎

 mysql>select count(*) as cnt,table_schema,engine from information_schema.tables where table_schema not in('mysql','information_schema','PERFORMANCE_SCHEMA') group by table_schema,engine order by cnt desc;

(4)查看所有表的存儲引擎

 mysql>select table_schema,table_name,engine,TABLE_ROWS,AVG_ROW_LENGTH,DATA_LENGTH,INDEX_LENGTH from information_schema.tables where table_schema not in('mysql','information_schema','PERFORMANCE_SCHEMA') order by table_schema,TABLE_ROWS desc;

 

(5)查看線程狀態
mysql> show full processlist;

(6)如果第5步有不少SQL經常能看到,把那些SQL的執行計划也收集下,以及相應表的DDL
mysql> explain select....
mysql> show create table table_name;
mysql> show index from table_name;

(7)提供慢日志統計結果
mysqldumpslow slow.log > slow-stat.log
slow.log文件名改成你真正的慢日志文件名

 

(8)查看死鎖

監控死鎖

 

#pt-deadlock-logger--ask-pass --run-time=10 --interval=3 --create-dest-table --dest D=test,t=deadlocks u=root,P=3306,h=127.0.0.1
查看死鎖
mysql>select *  from deadlocks\G;
 
               
5.檢查主從同步
(1)從庫檢查同步狀態
檢查Slave_IO_Running和Slave_SQL_Running是否都為YES
mysql>show slave status\G;

首先Master_Log_File和Relay_Master_Log_File所指向的文件必須一致。

其次Relay_Log_Pos和Exec_Master_Log_Pos的為止也要一致才行。

 

(2)主從數據校驗

 

mysql數據校驗
主庫執行
pt-table-checksum -uroot  --ask-pass --recursion-method=processlist --recurse=1  --no-check-binlog-format --nocheck-replication-filters --resume --max-lag=10
 
從庫:
select * from percona.checksums where master_cnt <> this_cnt OR master_crc <> this_crc OR ISNULL(master_crc) <> ISNULL(this_crc);

 

6.PXC集群檢查

(1)查看Galera集群每個節點狀態

mysql>show status like 'wsrep%';

 

wsrep_cluster_status狀態為Primary

 

wsrep_connected為ON

wsrep_cluster_state_uuid:在集群所有節點的值應該是相同的

 

wsrep_local_state_comments是否為 Synced 表示節點處於工作狀態
 
(2)查看每個節點的4567端口
#lsof -i :4567
查看每個節點的4567端口和其他節點都是互通的
 
7.MHA檢查

 

(1)檢查啟動的狀態

 

masterha_check_status --conf=/etc/masterha/app1.cnf
 

 

 

 

(2)masterha_check_ssh驗證ssh信任登錄是否成功

 

masterha_check_ssh --conf=/etc/masterha/app1.cnf

(3)masterha_check_repl驗證mysql復制是否成功  

 

 

masterha_check_repl --conf=/etc/masterha/app1.cnf
 

8.查看日志
(1)查看報錯日志

mysql> show variables like 'log_error';

#cat mysqlerr.log |grep -i -C 5 ERROR

 

 

 

(2)查看備份日志 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM