close
所有作業是在centos的環境下完成
利用Maatkit中的mk-heartbeat搭配cacti來進行mysql replication的監控

前置作業*mysql replication需已運作完成
1.安裝epel來源
2.yum install Maatkit
3.在msater登入mysql 
  #建立一個db 
  create database maatkit;  #需在replication範圍內
  #利用mk-heartbeat自己建table
  mk-heartbeat -u XXX -p XXXX --database maatkit --table heartbeat --update --create-table -h localhost
運作原理
  在master持續更新一張表並在裡面插入時間 mysql replication會自動同步去slave 透過slave去查詢這張表並比對時間 因為網路傳輸的關係所以預設會容許一秒的誤差

4.更新內容指令 (加上&背景執行)
  mk-heartbeat -D maatkit --table heartbeat -u XXX -p XXXX --update -h localhost &
  開機自動執行將上面指令直接加入/etc/rc.local
5.slave設定開始 請重覆step1~2完成安裝Maatkit動作
  執行
  mk-heartbeat -D maatkit --table heartbeat -u xxx -p xxxx --monitor -h localhost
  假如沒有任何lag 畫面輸出會長這樣
  0s [  0.00s,  0.00s,  0.00s ]
  0s [  0.00s,  0.00s,  0.00s ]
  0s [  0.00s,  0.00s,  0.00s ]
  0s [  0.00s,  0.00s,  0.00s ]
  0s [  0.00s,  0.00s,  0.00s ]
  0s [  0.00s,  0.00s,  0.00s ]
  0s [  0.00s,  0.00s,  0.00s ]
  0s [  0.00s,  0.00s,  0.00s ]
  指令最後加上--file 檔名 可以將結果存檔
  或是直接執行這命令會得到結果  
  mk-heartbeat -D maatkit --check -hlocalhost -uxxx -pxxxx
  0

CACTI 安裝 better-cacti-templates-1.1.8.tar.gz
到這邊找新版本
  http://code.google.com/p/mysql-cacti-templates/downloads/list
解壓後
  scripts\ss_get_mysql_stats 上傳到cacti的scripts目錄下
  修改41行 $heartbeat  = '';填入之前建的db.table name 
載入xml檔
  template\cacti_host_template_x_mysql_server_ht_0.8.6i-sver1.1.8.xml
在Console -> Data Templates 找到X MySQL Replication DT
  最下面的Custom Data [data input: X Get MySQL Stats/MySQL Replication IM]
  Hostname Password Port Username全部勾Use Per-Data Source Value (Ignore this Value)
在Console->Data Input Methods內,把所有有關mysql數據項的Port都改成不請允許爲空。
  Allow Empty Input 取消選取
接著就可以新增圖表在新增時會要求輸入Hostname Password Port Username等相關資訊

參考資料:
http://www.l2tp.org/?p=2217
http://www.onaxer.com/2010/07/08/mysql-replication-monitoring/
http://blog.chinaunix.net/uid-22861548-id-3285915.html
http://blog.chinaunix.net/uid-17282739-id-3168299.html
http://negiup.blog.51cto.com/2348622/51666
http://www.sbear.cn/archives/tag/maatkit/page/2
http://tc.itkee.com/database/detail-1893.html
http://andorian.blogspot.tw/2010/03/monitoring-mysql-replication-with-mk.html
 



  
arrow
arrow
    全站熱搜

    紐士比 發表在 痞客邦 留言(0) 人氣()