MySQL MHA高可用环境搭建(5)


(3) 编辑脚本send_report,修改后如下:
#!/usr/bin/perl
use strict; 
use warnings FATAL => 'all';   
use Mail::Sender;   
use Getopt::Long;
#new_master_host and new_slave_hosts are set only when recovering master succeeded 
my ( $dead_master_host, $new_master_host, $new_slave_hosts, $subject, $body );   
my $smtp='smtp.163.com';   
my $mail_from='xxxx';   
my $mail_user='xxxxx';   
my $mail_pass='xxxxx';   
my $mail_to=['xxxx','xxxx'];   
GetOptions(   
  'orig_master_host=s' => \$dead_master_host,   
  'new_master_host=s'  => \$new_master_host,   
  'new_slave_hosts=s'  => \$new_slave_hosts,   
  'subject=s'          => \$subject,   
  'body=s'            => \$body,   
);
mailToContacts($smtp,$mail_from,$mail_user,$mail_pass,$mail_to,$subject,$body);
sub mailToContacts { 
    my ( $smtp, $mail_from, $user, $passwd, $mail_to, $subject, $msg ) = @_;   
    open my $DEBUG, "> /tmp/monitormail.log"   
        or die "Can't open the debug      file:$!\n";   
    my $sender = new Mail::Sender {   
        ctype      => 'text/plain; charset=utf-8',   
        encoding    => 'utf-8',   
        smtp        => $smtp,   
        from        => $mail_from,   
        auth        => 'LOGIN',   
        TLS_allowed => '0',   
        authid      => $user,   
        authpwd    => $passwd,   
        to          => $mail_to,   
        subject    => $subject,   
        debug      => $DEBUG   
    };
    $sender->MailMsg( 
        {  msg  => $msg,   
            debug => $DEBUG   
        }   
    ) or print $Mail::Sender::Error;   
    return 1;   
}
# Do whatever you want here
exit 0;
 
五、MHA的日常管理
1. 检查SSH配置(node5 Monitor 监控节点上操作),如下:
# masterha_check_ssh --conf=/etc/masterha/app1.cnf
Sun May  1 22:05:12 2016 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping. 
Sun May  1 22:05:12 2016 - [info] Reading application default configuration from /etc/masterha/app1.cnf..   
Sun May  1 22:05:12 2016 - [info] Reading server configuration from /etc/masterha/app1.cnf..   
Sun May  1 22:05:12 2016 - [info] Starting SSH connection tests..   
Sun May  1 22:05:14 2016 - [debug]   
Sun May  1 22:05:12 2016 - [debug]  Connecting via SSH from root@192.168.1.121(192.168.1.121:22) to root@192.168.1.122(192.168.1.122:22)..   
Sun May  1 22:05:13 2016 - [debug]  ok.   
Sun May  1 22:05:13 2016 - [debug]  Connecting via SSH from root@192.168.1.121(192.168.1.121:22) to root@192.168.1.123(192.168.1.123:22)..   
Sun May  1 22:05:13 2016 - [debug]  ok.   
Sun May  1 22:05:14 2016 - [debug]   
Sun May  1 22:05:13 2016 - [debug]  Connecting via SSH from root@192.168.1.122(192.168.1.122:22) to root@192.168.1.121(192.168.1.121:22)..   
Sun May  1 22:05:13 2016 - [debug]  ok.   
Sun May  1 22:05:13 2016 - [debug]  Connecting via SSH from root@192.168.1.122(192.168.1.122:22) to root@192.168.1.123(192.168.1.123:22)..   
Sun May  1 22:05:14 2016 - [debug]  ok.   
Sun May  1 22:05:14 2016 - [debug]   
Sun May  1 22:05:13 2016 - [debug]  Connecting via SSH from root@192.168.1.123(192.168.1.123:22) to root@192.168.1.121(192.168.1.121:22)..   
Sun May  1 22:05:14 2016 - [debug]  ok.   
Sun May  1 22:05:14 2016 - [debug]  Connecting via SSH from root@192.168.1.123(192.168.1.123:22) to root@192.168.1.122(192.168.1.122:22)..   
Sun May  1 22:05:14 2016 - [debug]  ok.   
Sun May  1 22:05:14 2016 - [info] All SSH connection tests passed successfully.

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/33f1d15d8837f955282f8c830e136209.html