標籤:blank display border 資料庫 target
早上收到zabbix警示,發現某台存放監控資料的資料庫主機CPU的IOwait較高,一直持續較長時間。
650) this.width=650;" style="background-image: none; display: inline" title="image" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M01/8E/5B/wKiom1i-W9rjoJG7AAGr09LftGA628.png" "1028" height="258" />
登入伺服器查看磁碟IO發現隊列高達90%多,而且經常反覆如此
650) this.width=650;" style="background-image: none; display: inline" title="image" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M02/8E/5B/wKiom1i-W-3BUox4AAcFQvjFBNw098.png" "1028" height="811" />
通過iotop查看發現佔用io較大的進程是mysql
650) this.width=650;" style="background-image: none; display: inline" title="image" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M01/8E/59/wKioL1i-W-6zksjwAAE24wURii4413.png" "1028" height="79" />
登入mysql查看show processlist,發現基本上每次io隊列較高時都是在insert時,以為是插入語句有問題,於是開啟mysql慢查詢日誌,觀察一段時間磁碟io仍然較高,但是發現並沒有任何慢查詢語句;
尋找關於mysql IO問題最佳化資料,《【轉載】sync_binlog和innodb_flush_log_at_trx_commit 淺析》說到 sync_binlog和innodb_flush_log_at_trx_commit 兩個參數,這兩個參數是控制MySQL 磁碟寫入策略以及資料安全性的關鍵參數
650) this.width=650;" style="background-image: none; display: inline" title="image" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M01/8E/5B/wKiom1i-XDnxpCSLAAPEpTKkqPw263.png" "844" height="539" />
由於這台主機作為監控服務資料庫,所以在部署之初沒有做太多最佳化,配置基本保持預設,所以在每次事務提交都對應一次寫操作,導致寫操作太過頻繁。
於是修改sync_binlog和innodb_flush_log_at_trx_commit參數
set global sync_binlog=500; set global innodb_flush_log_at_trx_commit=2;
修改完sync_binlog和innodb_flush_log_at_trx_commit兩個參數後,觀察一段時間發現CPU的IOwait明顯降低
650) this.width=650;" style="background-image: none; display: inline" title="image" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M02/8E/5B/wKiom1i-XDqxfh9gAAE75tn-MVY901.png" "1028" height="258" />
Mysql佔用大量寫I/O