In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you what the Keepalived email notification configuration in the high availability service is like, which is concise and easy to understand. I hope you can gain something through the detailed introduction of this article.
Today we're going to talk about keepalived's email notification configuration.
A highly available service should have the ability to fail over immediately when the service fails, so as to ensure the availability of the service. at the same time, it should also notify the administrator as soon as possible, so that the administrator can know that the service has been transferred. In this way, the administrator can also troubleshoot the fault as soon as possible, so that the failed node can be brought back online in a very short time, so as to avoid the service being unavailable due to the next failure. Keepalived's fault notification mail mechanism triggers mail notifications by judging the role of the current node keepalived.
Mail Notification configuration for keepalived
Notification_email {...}: this directive is used to apply a configuration segment of a message recipient, enclosed in curly braces, in which multiple mail recipients can be configured.
Notification_email_from: this directive is used to specify the mailbox of the sender of the message
Smtp_server: this directive is used to specify the mail server address
Smtp_connect_timeout: this directive is used to specify the timeout for connecting to the mail server. The default is 30 seconds.
Notify_master: configure an action triggered by a node to become a master role; usually to execute a script
Notify_backup: configure the actions triggered by the conversion of node roles to backup
Notify_fault: configure an action triggered by a node in a failed state
Example: configure node01 in case of failover, the mail recipient is the local root user, the mail server address is 127.0.0.1, and the mail sender is node01_keepalived@localhost
1. Write an email notification script
26 [root@node01 keepalived] # cat notify.sh
#! / bin/bash
#
Contact='root@localhost'
Notify () {
Local mailsubject= "$(hostname) to be $1, vip floating"
Local mailbody= "$(date +'% F% T'): vrrp transition, $(hostname) changed to be $1"
Echo "$mailbody" | mail-s "$mailsubject" $contact
}
Case $1 in
Master)
Notify master
Backup)
Notify backup
Fault)
Notify fault
*)
Echo "Usage: $(basename $0) {master | backup | fault}"
Exit 1
Esac
[root@node01 keepalived] #
Tip: this script mainly implements sending messages with different contents according to different parameters passed.
Add execution permission to the script and copy the script from node01 to node02
Install the mail command
50 [root@node01 keepalived] # mail
-bash: mail: command not found
[root@node01 keepalived] #
[root@node01 keepalived] # yum install mailx
Loaded plugins: fastestmirror
Base | 3.6 kB 00:00:00
Docker-ce-stable | 3.5 kB 00:00:00
Epel | 4.7 kB 00:00:00
Extras | 2.9 kB 00:00:00
Updates | 2.9 kB 00:00:00
(1x2): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(2x2): epel/x86_64/primary_db | 6.9 MB 00:00:01
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
-> Running transaction check
-> Package mailx.x86_64 0RU 12.5-19.el7 will be installed
-> Finished Dependency Resolution
Dependencies Resolved
=
Package Arch Version Repository Size
=
Installing:
Mailx x8631 64 12.5-19.el7 base 245k
Transaction Summary
=
Install 1 Package
Total download size: 245 k
Installed size: 466 k
Is this ok [y/d/N]: y
Downloading packages:
Mailx-12.5-19.el7.x86_64.rpm | 245kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing: mailx-12.5-19.el7.x86_64 1 Compact 1
Verifying: mailx-12.5-19.el7.x86_64 1 Compact 1
Installed:
Mailx.x86_64 0RU 12.5-19.el7
Complete!
[root@node01 keepalived] #
Tip: you also need to install the mailx package in node02 so that it can send mail through mail.
Verification: manually pass the master | backup parameter to the script to test whether it is possible to send mail on this machine. Can native root users receive email?
Tip: you can see that we give the script a master parameter, which notifies the local root user by mail; the mail script is ready at this point.
Configure keepalived Mail Notification
Configure recipients and senders of keepalived messages
Tip: the above configuration means that when a failover occurs, the recipient of the mail notification is root@localhost, the sender is node01_keepalived@localhost, the address of the mail server is 127.0.0.1, and the timeout is 30 seconds.
The script that triggers execution when a failover occurs in the configuration keepalived
Tip: the above configuration means that when vrrp VI_1 fails over, if you change from the master role to the backup role, the notify_backup instruction will be triggered to send an email with the specified script and parameters If you change from a backup role to a master role, it will trigger the script and parameters specified in the notify_master instruction to send the email, and if the current node transitions from the master or backup role to the fault state, it will trigger the notify_fault instruction to say the specified script and parameters to send the email.
Verify: start the keepalived of node01 to see if an email will be sent?
Tip: you can see from the status information of keepalived that script execution has been triggered.
Open the root user's mailbox to see if there is a failover to the message?
Tip: you can see that an email has been received, telling us that all node01 has changed from backup to master.
Add mail notification configuration to node02
Start keepalived on node02
Stop keepalived on node01 and see if you get an email on node02.
Zhengzhou painless abortion Hospital http://www.tjyy120.com/
Tip: you can see that when the node01 node service fails, it transfers the vip to the node02, and the node02 changes from the backup role to the master role, triggering the script and parameters specified in the notify_master directive to send the email.
Example: configure keepalived to send mail to a specified Internet mailbox in the event of a failover
Configure the mail client
Tip: after configuring the above configuration, you can use 467697313@qq.com on node01 and node02 to send mail to the mailbox specified in the script; to configure the mailbox client, you need to open POP3/SMTP in the corresponding mailbox, and then after authentication, it will tell us a string of smtp-auth-password.
Tip: the mail client is configured at this point.
Modify the mailbox of the recipient in the script to an Internet mailbox which is a good http://www.zzchfk.com/ for painless abortion in Zhengzhou
Tip: after modifying the mail recipient, if the keepalived on node01 or node02 fails over, it will send mail to our designated recipient with our configured mail client.
Verify: start keepalived on node01 to see if you will receive an email from linux1874@qq.com in your linux_test01@126.com mailbox. Is the content of the email what we specified in the script?
Tip: you can see that after starting keepalived on node01, the keepalived on the corresponding node01 changes from stop state to master state, and the specified script is also triggered
Open the linux_test01@123.com mailbox and see if you received the email?
Tip: you can see that in the mailbox of linux_test01@126.com, three emails were received, the first one was sent to email from node01 to backup status, the second was sent to email from master role to backup role, and the third was the email sent by node01 from backup role to master. At this point, the keepalived configuration email client based on mail configuration to send failover notification messages to Internet mailboxes has been tested.
The above is what the Keepalived email notification configuration looks like in high-availability services. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.