12組nodes MySQL DB,每組2台Master-Master,批量清除到期的binlog釋放磁碟空間

來源:互聯網
上載者:User



方案,總共24台db,一台台進去清理肯定不行,得需要寫一個指令碼,進行大量操作,方案思路大概如下

1,  建立雙master列表masterlist; 一個master一行。

2,遠程擷取master db上面的binlog位置以及對應master的master主機名稱(也許是ip地址)

3,拿到binlog位置以及master主機名稱,然後ssh遠程清理掉遠程master上面的binlog

4, shell for迴圈操作step 2以及step 3。

for masterdb in `cat master.db.full`;do#1 echo get the binlog position infomationstr_log_files=`ssh $masterdb "/opt/mysql/product/5.5.25a/bin/mysql -uroot --password="" -e \"show slave status\G;\" |grep -i master_Log_File "`echo $str_log_files;log_file=`echo $str_log_files | awk '{print $2}'`; echo $log_file;#2 echo get the master ip address or master hostnamedb01tmp=`ssh $masterdb "  /opt/mysql/product/5.5.25a/bin/mysql  -uroot  --password=""  -e \"show slave status\G;\" |grep -i Master_Host  "`;  db01=`echo $db01tmp | awk '{print $2}'`#3 begin to clear the old binlog ssh $db01 "/opt/mysql/product/5.5.25a/bin/mysql  -uroot  --password="" -e \"purge master logs to '$log_file';\""#4 check the disk space for masterssh $db01 "df -h"echo " "echo " -- -- -- ";done;

OK,run sh指令碼 

最後再次check disk space,執行check_disk.sh指令碼,指令碼內容如下:

for masterdb in `master.db.full`;do  ssh  $masterdb "df -h" |grep -i mysqldatadir;done;

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.