Postfix 是一套快速, 安全及容易管理的開源 Mail Transfer Agent (MTA), 也是 Sendmail 很好的替代品。以下會介紹在 RHEL 及 CentOS 7 安裝 Postfix 及 Dovecot 作為 Email Server.
在開始前, 如果系統內安裝了其他 MTA (例如 Sendmail 或 Exim), 那便需要將它們移除, 以下是移除 Sendmail 及 Exim 的方法:
Sendmail:
|
1 |
# yum remove sendmail |
Exim:
|
1 |
# yum remove exim |
為了使安裝過程簡單一點, 關閉 SELinux, 開啟 /etc/sysconfig/selinux, 將:
“SELINUX=enforcing”
換成:
“SELINUX=disabled”
SELINUX=disabled
現在開始安裝 Postfix, 執行以下指令可以十分簡單用 YUM 安裝 Postfix:
|
1 |
# yum install postfix |
安裝好 Postfix 後, 修改 Postfix 的設定, 開啟 /etc/postfix/main.cf, 修改以下設定:
myhostname:
將註解移除, 並改成系統的 hostname
mydomain:
將註解移除, 並改成系統的 domain name
myorigin:
改成 $mydomain
inet_interfaces:
改成 all
inet_protocols:
改成 all
mydestination:
改成 $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks:
設定網路, 例如 192.168.1.0/24, 127.0.0.0/8
home_mailbox:
改成 Maildir/
儲存檔案後離開文字編輯器, 然後設定 Postfix 開機自動執行及重新啟動:
|
1 2 |
# systemctl enable postfix # systemctl restart postfix |
安裝好 Postfix 後, 接著是安裝 Dovecot, Dovecot 是 Linux 的開源 IMAP, POP3 Email Server, 輸入以下指令用 YUM 安裝:
|
1 |
# yum install dovecot |
修改 Dovecot 設定, 開啟檔案 /etc/dovecot/dovecot.conf file, 找到 protocols, 將它刪除註解, 加入 pop3, imap, lmtp, 即這樣:
|
1 |
protocols = imap pop3 lmtp |
開啟檔案 /etc/dovecot/conf.d/10-mail.conf, 將 mail_location 改成這樣:
|
1 |
mail_location = maildir:~/Maildir |
開啟檔案 /etc/dovecot/conf.d/10-auth.conf, 將 disable_plaintexta_auth 及 auth_mechanisms 修改成:
|
1 2 |
disable_plaintext_auth = yes auth_mechanisms = plain login |
開啟檔案 /etc/dovecot/conf.d/10-master.conf, 修改 user 及 group:
|
1 2 |
user = postfix group = postfix |
儲存檔案後離開文字編輯器, 然後設定 Dovecot 開機自動執行及重新啟動:
|
1 2 |
# systemctl enable dovecot # systemctl start dovecot |
現在 Postfix 及 Dovecot 已經安裝完成。