最近在研究服務器高可用集群 (HA)……
嘗試配置keepalived,
卻發現其全局配置(global_defs )中發送郵件的SMTP服務器配置只有簡單 smtp_server 一個選項。
那么,如果希望使用外部郵箱(比如 163郵箱)或需要用戶名密碼認證的郵箱發送提醒郵件該如何配置?
以“keepalived smtp auth”為關鍵詞 Google之 ……
看到keepalived作者對這個問題的看法:I dont see urgent matter for this ……
不過issues中也給出了解決方案 :
Install a MTA like Postfix and securely relay any message to the company's SMTP server.
遂,經過 “精挑細選”……決定用 Postfix 搭一個MTA,作為網易郵箱的代理,最終實現使用keepalived中自帶郵件通知機制進行通知提醒。
Postfix 是一種電子郵件服務器,它是由任職於IBM華生研究中心(T.J. Watson Research Center)的荷蘭籍研究員Wietse Venema為了改良sendmail郵件服務器而產生的。最早在1990年代晚期出現,是一個開放源代碼的軟件。
以下才是是重點:
測試環境:CentOS-6.8-x86_64-minimal
安裝Postfix :
> yum install postfix mail cyrus-sasl-* -y
配置Postfix:
> vi /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
> vi /etc/postfix/sasl_passwd
(郵箱賬號和密碼文件,每行一個。 創建好后需要使用postmap命令使配置文件生效)
[smtp.163.com]:25 guang384@163.com:my163Password
> postmap /etc/postfix/sasl_passwd
> vi /etc/postfix/sender_canonical
(linux用戶和發件人對應關系,每行一個)
root guang384@163.com
> postmap /etc/postfix/sender_canonical
重啟Postfix:
> service postfix restart
嘗試發送郵件:
>echo "hello world" |mail -s test guang384@qq.com
(可以用 mailq 命令查看發送隊列,清空mailq隊列 : postsuper -d ALL )

