12组nodes MySQL DB,每组2台Master-Master,批量清除过期的binlog释放磁盘空间
方案,总共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 infomation
str_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 hostname
db01tmp=`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 master
ssh $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;
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。