专栏目录
- keepalived简介[使用keepalived搭建nginx主备]
- centos7安装keepalived[使用keepalived搭建nginx主备]
- keepalived配置详解[使用keepalived搭建nginx主备]
- keepalived守护nginx[使用keepalived搭建nginx主备]
- keepalived邮件通知[使用keepalived搭建nginx主备]
- keepalived主备配置[使用keepalived搭建nginx主备]
安装邮件服务
yum install mailx -y
配置邮件账户
vim /etc/mail.rc
set from=youremail@sina.com #发件人邮箱地址(sina设置在sina邮箱中开启允许代理)
set smtp=smtp.sina.com #smtp地址
set smtp-auth-user=youremail@sina.com #邮箱用户名,不用加域名
set smtp-auth-password=****** #邮箱密码(邮件密码是smtp代理授权码)
set smtp-auth=login #邮箱验证方式
测试邮件发送
echo "hello world" | mail -s "hello" 498886724@qq.com
配置邮件发送脚本
这里请灵活的切换为你的ip和收件箱
vim /etc/keepalived/mail_notify.sh
#!/bin/bash
echo "192.168.1.203 $1 状态被激活,请确认keepalived服务运行状态"|mail -s "keepalived状态切换警告" youreamil@qq.com
脚本授权
chmod 777 /etc/keepalived/mail_notify.sh
修改keepalived配置
这里请灵活的切换,是否启动的时候发送邮件等
vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state MASTER
interface enp0s3
virtual_router_id 51
priority 100
advert_int 1
#Keepalived进入MASTER状态执行脚本
notify_master "/etc/keepalived/mail_notify.sh master"
#Keepalived进入BACKUP状态执行脚本
notify_backup "/etc/keepalived/mail_notify.sh backup"
#Keepalived进入FAULT状态执行脚本
notify_fault "/etc/keepalived/mail_notify.sh fault"
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_http_port
}
virtual_ipaddress {
192.168.200.203
}
}
启动keepalived生效
/usr/sbin/keepalived
所有文章都是以专栏系列编写,建议系统性学习,更容易成为架构师!
博主每天早晚坚持写博客给与读者价值提升,为了让更多人受益,请多多关照,如果觉得文章质量有帮助到你,请关注我的博客,收藏此文,持续提升,奥利给!
另外我不打算靠运营方式拿到博客专家的认证,纯纯的科技与狠活来征服读者,就看读者的感恩之心了,祝你好运连连。