MySQL High Availability MHA (supplemental 2)--mail alarm

Source: Internet
Author: User
Tags failover

When MHA is done failover or due to an error stop, we can use Send_report to get the failover report in the form of an email alert so that we know the current database status in a timely manner.

You first need to modify the script:

[[email protected] mha]# cat/usr/local/bin/send_report #!/usr/bin/perl# Copyright (C) DeNA co.,ltd.## this PR Ogram is free software; Can redistribute it and/or modify# it under the terms of the GNU general public License as published by# Ftware Foundation; Either version 2 of the License, or# (at your option) any later version.## this program was distributed in the hope It'll be useful,# and without any WARRANTY;  Without even the implied warranty of# merchantability or FITNESS for A particular PURPOSE. See the# GNU General public License-details.## you should has received a copy of the GNU General public Licens e# along with this program; If not, write to the free software# Foundation, inc.,# Wuyi Franklin Street, Fifth Floor, Boston, MA 02110-1301 usa## No Te:this is a, a sample script and is not complete. Modify the script based on your environment.use strict;use warnings FATAL = ' All ', use mail::sender;use getopt::long; #n Ew_masTer_host and New_slave_hosts is set only when recovering Master succeededmy ($dead _master_host, $new _master_host, $new _s Lave_hosts, $subject, $body); my $smtp = ' smtp.163.com '; my $mail _from= ' [email protected] '; my $mail _user= ' [email  protected] '; my $mail _pass= ' password '; #my $mail _to=[' [email protected] ', ' [email protected] '];my $ Mail_to= ' [email protected] '; GetOptions (' orig_master_host=s ' + \ $dead _master_host, ' new_master_host=s ' + \ $new _master_host, ' New_slave_ho  Sts=s ' + \ $new _slave_hosts, ' subject=s ' + \ $subject, ' body=s ' and ' = $body, '); # do whatever You want Heremailtocontacts ($SMTP, $mail _from, $mail _user, $mail _pass, $mail _to, $subject, $body); Sub Mailtocontacts {my ($SMTP, $mail _from, $mail _user, $mail _pass, $mail _to, $subject, $msg) = @_;open my $DEBUG, ">/var/log/masterha/app1/ma Il.log "or die" Can ' t open the debugfile:$!\n "; my $sender = new Mail::sender {ctype=> ' Text/plain;charset=utf-8 ', Encodi Ng=> ' Utf-8 ', smtp=> $smtp,from=> $mail _from,auth=> ' LOGIN ',tls_allowed=> ' 0 ',authid=> $mail _user,authpwd=> $mail _pass,to=> $mail _to,subject=> $subject,debug=> $DEBUG}; $sender->mailmsg ({msg = $msg, debug = $ DEBUG}) or print $Mail:: Sender::error;return 1;} Exit 0;
Then modify the configuration file, just add Report_script to

[Server Default]manager_log=/var/log/masterha/app1/manager.logmanager_workdir=/var/log/masterha/app1master_ Binlog_dir=/data/mysqlmaster_ip_failover_script=/usr/local/bin/master_ip_failovermaster_ip_online_change_ script=/usr/local/bin/master_ip_online_changepassword=123456ping_interval=1remote_workdir=/tmprepl_password= 123456repl_user=repreport_script=/usr/local/bin/send_reportssh_port=22ssh_user=rootuser=mha[server1]hostname= 10.10.10.56port=3306[server2]hostname=10.10.10.57port=3306[server3]hostname=10.10.10.58port=3306
Finally turn on MHA monitoring, stop master to trigger failover, at the end we can see the failover report generated and send_report.

-----Failover Report-----app1:mysql Master Failover 10.10.10.57 (10.10.10.57:3306) to 10.10.10.56 (10.10.10.56:3306) Succeededmaster 10.10.10.57 (10.10.10.57:3306) is down! Check MHA Manager logs at Rd-mysql-test4:/var/log/masterha/app1/manager.log for details. Started Automated (non-interactive) failover. Invalidated master IP address on 10.10.10.57 (10.10.10.57:3306) The latest slave 10.10.10.56 (10.10.10.56:3306) have all RelA y logs for recovery. Selected 10.10.10.56 (10.10.10.56:3306) as a new master.10.10.10.56 (10.10.10.56:3306): ok:applying all logs succeeded.10 .10.10.56 (10.10.10.56:3306): ok:activated master IP address.10.10.10.58 (10.10.10.58:3306): This host has the latest RelA Y log events. Generating relay diff files from the latest slave succeeded.10.10.10.58 (10.10.10.58:3306): ok:applying All logs succeeded . Slave started, replicating from 10.10.10.56 (10.10.10.56:3306) 10.10.10.56 (10.10.10.56:3306): Resetting Slave Info Succeeded. Master failover to 10.10.10.56 (10.10.10.56:3306) complEted successfully. Thu 11:27:36-[info] sending mail. Unknown option:conf
We received the following email:

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

MySQL High Availability MHA (supplemental 2)--mail alarm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.