最近在用keepalived做haproxy高可用的时候,发现keepalived默认是有发送邮件设置的。但是一番百度之后发现都是通过脚本来实现的邮件报警。功夫不负有心人,最终还是成功使用keepalived默认报警设置实现了报警。现在记录如下:

环境centos6.5

1、默认报警调用了postsfix。我的机器默认安装了postsfix服务并开启,但是日志一直显示发送不成功


2、解决方法

安装Postfix :

yum install postfix mail cyrus-sasl-* -y

修改postsfix配置文件 /etc/postfix/main.cf(postfix主要配置文件

在其末尾添加以下内容

#指定默认的邮件发送服务器
relayhost = [smtp.163.com]:25
#激活sasl认证
smtp_sasl_auth_enable = yes
#指定sasl密码配置文件
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
#非匿名登录smtp_sasl_security_options = noanonymous
#指定认证类型 (提示:需要yum安装cyrus-sasl-*组件,否则发邮件时会报错:no mechanism available)
smtp_sasl_type = cyrus
#linux用户与发件人的对应关系配置文件
sender_canonical_maps = hash:/etc/postfix/sender_canonical

编辑 /etc/postfix/sasl_passwd(邮箱账号和密码文件,每行一个。 创建好后需要使用postmap命令使配置文件生效

添加以下内容

[smtp.163.com]:25   admin@163.com:password

编辑 /etc/postfix/sender_canonical(linux用户和发件人对应关系,每行一个)

root   admin@163.com

将文本文件转换为hash格式的查找表文件。

#postmap /etc/postfix/sasl_passwd
#postmap /etc/postfix/sender_canonical

重启postfix:

service postfix restart

至此postfix设置完毕,测试keepalived即可正常发送报警邮件。