萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 伺服器教學

CentOS 下 Postfix + Dovecot + Amavisd + ClamAV 郵件系統完整部署教程

架構概覽

  • MTA:Postfix(收發信)
  • MDA/IMAP/POP3:Dovecot
  • 內容過濾:Amavisd-new(整合 SpamAssassin、ClamAV)

1. 安裝 Postfix 並基本配置

yum install postfix system-switch-mail
vi /etc/postfix/main.cf
myhostname = mail.example.com
myorigin = $myhostname
myorigin = example.com
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost
mynetworks = 192.168.1.0/24, 127.0.0.0/8
relay_domains = $mydestination

設定開機自啟:

echo "/usr/sbin/postfix start" >> /etc/rc.d/rc.local

2. 安裝與配置 Dovecot (CentOS 6.4)

yum -y install dovecot
cp /etc/dovecot.conf /etc/dovecot.conf.bak
vi /etc/dovecot.conf
protocols = pop3
ssl_disable = yes

信箱儲存位置:

vi /etc/dovecot/conf.d/10-mail.conf
mail_location = mbox:~/mail:INBOX=/var/mail/%u

認證設定:

vi /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = plain login
service dovecot restart
chkconfig dovecot on

3. Postfix SMTP 驗證 (SASL)

vi /etc/postfix/main.cf
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
chkconfig saslauthd on
service saslauthd restart

4. 病毒與垃圾郵件過濾:Amavisd-new + ClamAV

yum -y install clamav amavisd-new
service clamd start
chkconfig --level 3,5 freshclam on
service amavisd start
chkconfig --level 3,5 amavisd on

指定郵件域:

vi /etc/amavisd/amavisd.conf
$mydomain = 'example.com';

5. Postfix 整合 Amavisd(master.cf)

vi /etc/postfix/master.cf
# 定義 amavis 服務
amavis unix - - - - 2 smtp
    -o smtp_data_done_timeout=1200

# 接收掃描後郵件的專用 SMTP 埠
127.0.0.1:10025 inet n - n - - smtpd
    -o content_filter=
    -o local_recipient_maps=
    -o relay_recipient_maps=
    -o smtpd_restriction_classes=
    -o smtpd_client_restrictions=
    -o smtpd_helo_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o mynetworks=127.0.0.0/8
    -o strict_rfc821_envelopes=yes
    -o smtpd_error_sleep_time=0
    -o smtpd_soft_error_limit=1001

並在 main.cf 指定:

content_filter = smtp:127.0.0.1:10024

6. 驗證流程

  1. 發信 → Postfix (25) → Amavisd (10024) 掃描 → Postfix (10025) → 遞送給 Dovecot/外部。
  2. 查看 /var/log/maillog 確認 Passed CLEAN 或 Blocked SPAM。

備選:多重 Content Filter 串接

參考文章 Postfix 部署多個 Content Filter 方法,可將 MailGate、Altermime 等串接於 Amavisd 之前或之後。

copyright © 萬盛學電腦網 all rights reserved