以下是一個基于CentOS的郵件服務器案例分析,涵蓋基礎配置、安全加固及常見問題處理:
systemctl stop firewalld)和SELinux(sed -i 's/SELINUX.*/SELINUX=disabled/' /etc/selinux/config),確保網絡連通性。yum install postfix dovecot mariadb-server -y
Postfix配置
/etc/postfix/main.cf:
myhostname = mail.example.com
mydomain = example.com
inet_interfaces = all
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
systemctl restart postfix
postfix check
Dovecot配置
/etc/dovecot/dovecot.conf,啟用IMAP/POP3協議并指定郵件存儲路徑:protocols = imap pop3
mail_location = maildir:/Maildir
/etc/dovecot/dovecot-sql.conf.ext:driver = mysql
connect = host=localhost dbname=mail user=mail_admin password=yourpassword
systemctl restart dovecot
安全與防火墻
firewall-cmd --permanent --add-services=smtp,imap,pop3
firewall-cmd --reload
/etc/aliases實現郵件群發,例如將admin賬號設為多個用戶的別名。| 問題現象 | 可能原因 | 解決方法 |
|---|---|---|
| 無法發送郵件(Relay denied) | 未啟用SMTP認證或IP未授權 | 檢查/etc/postfix/main.cf中mynetworks和smtpd_relay_restrictions配置,重啟服務 |
| 郵件接收失?。–onnection refused) | 防火墻攔截或Dovecot服務異常 | 確認防火墻放行IMAP/POP3端口,檢查Dovecot日志(/var/log/dovecot.log) |
| 郵件顯示亂碼 | 字符集配置錯誤 | 在Postfix的main.cf中添加charset = utf-8,或在郵件客戶端設置對應編碼 |
chown -R username:username /home/username/Maildir)。/var/log/maillog,及時發現異常登錄或郵件堆積問題。參考來源: