If 10 units within the DB, you manually ssh in, clean is enough, but hundreds of units, it is necessary to write a script. Approximate idea: In a DB jump connection above, write a script, access slave, remotely get the copy of the master above the Binlog location, and then remote to purge master above the Binlog.
1, establish slave dbserver list slavelist; A slave line.
2, remotely obtain the Binlog location above slave db and the master hostname of slave (perhaps an IP address)
3, get Binlog location and master hostname, and then ssh remotely clean up the Binlog on master
4, Shell forloop operation Step 2 and step 3.
Companion script 1:clean_binlog.sh
[Python]View PlainCopyprint?
- #!/bin/bash
- # p1 the slave MySQL DB server
- db03=$1
- Echo $dbserver;
- ster_log_file= ' ssh $db 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 ##### Get binlog Info
- Log_file= ' echo $ster _log_file | awk ' {print $} ';
- db01tmp= ' ssh $db 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]View PlainCopyprint?
- # get Master host name or IP address
- Db01= ' echo $db 01tmp | awk ' {print $} '
- # Start cleaning up Binlog log information
[Python]View PlainCopyprint?
- SSH $db "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 '; \" "
- # Binlog information on Check master
[Python]View PlainCopyprint?
- SSH $db "Df-h/mysql/binlog";
[Python]View PlainCopyprint?
- <strong><span style="color: #ff0000;" ></span></strong>
Included with batch for loop script 2:
For S in ' Cat slavelist '; do sh clean_binlog.sh $s; Done
This is a relatively rough plan, there must be shortcomings, my 128 group is a mm combination, so the operation is possible, the structure of different estimates will be changed, here is also related to purge before the Binlog backup and so on (with a dedicated backup machine and backup script).
How to bulk clear the expired Binlog above the 128 Group node DB and free up disk space. Go