Mysql Replication Slave Cheacker
Attension This Script modify /etc/hosts
1. All slave must be marked by add at the end of slave line in /etc/hosts ##SLAVE Example
1.2.3.4 slave ##SLAVE
ping slave get 1.2.3.4
#1.2.3.4 slave ##SLAVE and ping slave get 1.2.3.5
#!/usr/bin/perl -w
use strict;
use DBI;
my $user = 'root';
my $pass = '*****';
my $error = 'none';
sub check_slave {
my $dbh = DBI->connect("dbi:mysql:host=".shift, $user, $pass) or return 0;
my $i = $dbh->selectrow_hashref("SHOW SLAVE STATUS");
$error = 'Slave SQL not running';
return 0 if (exists $i->{Slave_SQL_Running} and $i->{Slave_SQL_Running} eq 'No');
$error = 'Slave IO not running';
return 0 if (exists $i->{Slave_IO_Running} and $i->{Slave_IO_Running} eq 'No');
$error = 'Unknown error';
if (exists $i->{Seconds_Behind_Master} and defined($i->{Seconds_Behind_Master})){
return 1 if ($i->{Seconds_Behind_Master}<10);
$error = 'Slave to far from master['.$i->{Seconds_Behind_Master}.']';
}
return 0;
}
sub trim {
my $s = shift;
for ($s) { s/^\s+//; s/\s+$//; }
return $s;
}
open HOSTS_IN, "/etc/hosts";
open HOSTS_OUT, ">/etc/hosts_new";
while (When you ready change last line to mv to /etc/hosts
Файлов нет.
[Показать файлы/форму]
Комментариев нет.
[Показать комментарии/форму]
Powered by WackoWiki R4.0
|
|