Home > Database > Mysql Tutorial > 如何批量清除128组节点db上面的过期的binlog,释放磁盘空间_MySQL

如何批量清除128组节点db上面的过期的binlog,释放磁盘空间_MySQL

WBOY
Release: 2016-06-01 13:33:09
Original
846 people have browsed it

bitsCN.com

如何批量清除128组节点db上面的过期的binlog,释放磁盘空间

 

如果10台以内的db的话,自己手动ssh进去,clean就足以,但是上百台呢,就要写脚本了。大概思路:在 一台db跳转机上面, 写一个脚本,访问slave,远程获取正在复制的master上面的binlog位置, 然后再远程去purge master上面的binlog.

 

1,  建立slave dbserver列表 slavelist; 一个slave一行。

 

2,远程获取slave db上面的binlog位置以及slave的master主机名(也许是ip地址)

 

3,拿到binlog位置以及master主机名,然后ssh远程清理掉master上面的binlog

 

4,shell for循环操作step 2以及step 3。

 

附带脚本1:clean_binlog.sh

[python] 

#!/bin/bash  

# p1 the slave mysql db server  

  

db03=$1  

echo  $dbserver;  

  

ster_Log_File=`ssh $db03 "  mysql  -uxx  -pxx --ssl-ca=/opt/mysql/ssl/ca-cert.pem --s  

sl-cert=/opt/mysql/ssl/server-cert.pem --ssl-key=/opt/mysql/ssl/server-key.pem -e /"show slave status/G;/" |grep -i master_Log_File  

"`;  

  

# echo ##### 获取binlog信息  

log_file=`echo $ster_Log_File | awk '{print $2}'`;  

  

db01tmp=`ssh $db03 "  mysql  -uxx  -pxx --ssl-ca=/opt/mysql/ssl/ca-cert.pem --s  

sl-cert=/opt/mysql/ssl/server-cert.pem --ssl-key=/opt/mysql/ssl/server-key.pem -e /"show slave status/G;/" |grep -i Master_Host  

"`;  

[python] 

# 获取master主机名或者ip地址  

db01=`echo $db01tmp | awk '{print $2}'`  

  

# 开始清理binlog日志信息  

[python] 

ssh $db01 " mysql  -uxxx  -pxx --ssl-ca=/opt/mysql/ssl/ca-cert.pem --ssl-cert=/op  

t/mysql/ssl/server-cert.pem --ssl-key=/opt/mysql/ssl/server-key.pem -e /"purge master logs to '$log_file';/" "  

  

# check master上面的binlog信息  

[python] 

ssh $db01 "  df -h /mysql/binlog ";  

[python] 

   

 

附带批量for循环脚本2:

for s in `cat slavelist`; do sh clean_binlog.sh $s; done

 

这个是比较粗略的方案,肯定有不足之处,我的128组是mm组合,所以这样操作是可以的,架构不同估计会有变动,这里还涉及到purge之前的binlog的备份等等(有专门的备份机以及备份脚本)。

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template