CentOS7郵箱服務(wù)器搭建全流程詳解
環(huán)境準(zhǔn)備與組件說明
搭建郵箱服務(wù)器需安裝Postfix(SMTP服務(wù))、Dovecot(IMAP/POP3服務(wù))和SSL證書。建議使用獨(dú)立服務(wù)器并配置固定公網(wǎng)IP,系統(tǒng)需更新至最新版本:
yum update -y
Postfix郵件服務(wù)配置
1. 安裝Postfix并禁用默認(rèn)的Sendmail服務(wù):
yum install postfix -y
systemctl stop sendmail
systemctl disable sendmail
2. 修改主配置文件/etc/postfix/main.cf
:
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.yourdomain.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.yourdomain.com/privkey.pem
Dovecot郵件協(xié)議配置
1. 安裝Dovecot服務(wù):
yum install dovecot -y
2. 修改SSL配置/etc/dovecot/conf.d/10-ssl.conf
:
ssl = required
ssl_cert = </etc/letsencrypt/live/mail.yourdomain.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.yourdomain.com/privkey.pem
3. 配置認(rèn)證機(jī)制/etc/dovecot/conf.d/10-auth.conf
:
auth_mechanisms = plain login
!include auth-system.conf.ext
SSL證書部署
使用Certbot獲取Let's Encrypt免費(fèi)證書:
yum install certbot -y
certbot certonly --standalone -d mail.yourdomain.com
DNS解析設(shè)置要點(diǎn)
- 創(chuàng)建MX記錄指向郵件服務(wù)器域名
- 添加SPF記錄:v=spf1 mx -all
- 配置DKIM簽名記錄(需安裝opendkim)
- 設(shè)置PTR反向解析記錄
服務(wù)啟動(dòng)與測試
啟動(dòng)服務(wù)并設(shè)置開機(jī)自啟:
systemctl start postfix dovecot
systemctl enable postfix dovecot
使用telnet測試SMTP服務(wù):
telnet mail.yourdomain.com 25
EHLO yourdomain.com
客戶端配置建議使用Thunderbird或Outlook,選擇SSL/TLS加密協(xié)議,端口配置:
- IMAP: 993
- SMTP: 465
安全強(qiáng)化建議
- 啟用防火墻規(guī)則:firewall-cmd --permanent --add-service={smtp,smtps,imap,imaps}
- 配置Fail2ban防止暴力破解
- 定期檢查郵件日志:/var/log/maillog
- 實(shí)施SMTP身份驗(yàn)證機(jī)制