KeepAlived send e-mail notification failover VIP- Scheme 1

 

1, add the configuration in the configuration file keepalived

When configuring the trigger current node becomes the standby node in /etc/keepalived/keepalived.conf file /usr/local/sendmail.shscript

 

 

2, write e-mail notification script/usr/local/sendmail.sh

# ! / Usr / bin / perl -w 
use Net :: SMTP_AUTH;
 use strict;
 # the SMTP server 
My  $ mailhost = ' smtp.qq.com ' ;
 # Send mail mailbox 
My  $ mailfrom = ' 913 011 *** @qq .com ' ;
 # mail to be sent, you can fill a plurality of 
My  @mailto = ( ' 15773 241 *** @ 163.com ' , ' 913 011 *** @ qq.com ' );
 # message subject 
My  $ Subject= ' Keepalived up ON Backup ' ;
 # body of the message 
my  $ text = ' content of the notification ' ;
 # Send mail mailbox user 
my  $ the User = ' 913 011 *** @ qq.com ' ;
 # Send mail mailboxes authorization code 
my  the passwd $ = ' cozc ******** bceb ' ;

 & the SendMail (); 

Sub the SendMail () {
   My  $ SMTP = Net :: SMTP_auth-> new new ( $ the mailhost , the Timeout => 120 , the Debug => . 1) or die "Error .\n";
  $smtp->auth('LOGIN',$user,$passwd);
  foreach my $mailto(@mailto){
    $smtp->mail($mailfrom);
    $smtp->to($mailto);
    $smtp->data();
    $smtp->datasend("To:$mailto\n");
    $smtp->datasend("From:$mailfrom\n");
    $smtp->datasend("Subject:$subject\n");
    $smtp->datasend("\n");
    $smtp->datasend("$text\n\n");
    $smtp->dataend();
  }
  $smtp->quit;

}

Script executable permissions granted

 

chmod +755 sendmail.sh

 

3, you need to install Net :: SMTP_auth


send_mail.sh script written in Perl, you need to install the environment:

yum -y install perl-CPAN
cpan Net::SMTP_auth

Dependent on manual execution environment after the installation is complete at the script and see if you can successfully send e-mail

./usr/local/sendmail.sh

 

 

 


Reference address
https://www.jianshu.com/p/41b052cfd429
https://www.cnblogs.com/John-2011/p/7838794.html

Guess you like

Origin www.cnblogs.com/kiko2014551511/p/11528821.html