1. 首页 > Linux教程 > 正文

Linux教程FG510-Linux综合实战案例十六

内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。

风哥提示:

本文档介绍企业级邮件服务部署综合实战案例。

Part01-Postfix邮件服务器

1.1 Postfix安装配置

# 安装Postfix
[root@fgedu-mail ~]# yum install -y postfix dovecot

# 配置Postfix
[root@fgedu-mail ~]# cat > /etc/postfix/main.from PG视频:www.itpux.comcf << 'EOF' # 基本配置 myhostname = mail.fgedu.net.cn mydomain = fgedu.net.cn myorigin = $mydomain inet_interfaces = all inet_protocols = ipv4 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain # 网络配置 mynetworks = 127.0.0.0/8,更多学习教程公众号风哥教程itpux_com 192.168.1.0/24 relay_domains = # 邮箱配置 home_mailbox = Maildir/ mail_spool_directory = /var/mail # 安全配置 smtpd_sasl_auth_enable = yes smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_security_options = noanonymous smtpd_sasl_local_domain = $myhostname broken_sasl_auth_clients = yes # TLS配置 smtpd_tls_security_level = may smtpd_tls_cert_file = /etc/pki/tls/certs/mail.学习交流加群风哥微信: itpux-comcrt smtpd_tls_key_file = /etc/pki/tls/private/mail.key smtpd_tls_loglevel = 1 smtpd_tls_received_header = yes smtpd_tls_session_cache_timeout = 3600s smtpd_tls_session_cache_database = btree:/var/lib/postfix/smtpd_scache # 防垃圾邮件 smtpd_helo_required = yes smtpd_delay_reject = yes smtpd_helo_restrictions = permit_mynetworks, reject_invalid_helo_hostname smtpd_sender_restrictions = permit_mynetworks, reject_unknown_sender_domain smtpd_recipient_restrictions学习交流加群风哥QQ113257174 = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination # 限制配置 message_size_limit = 52428800 mailbox_size_limit = 1073741824 EOF # 配置master.cf [root@fgedu-mail ~]# cat >> /etc/postfix/master.cf << 'EOF' submission inet n - n - - smtpd -o syslog_name=postfix/submission -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes -o smtpd_tls_auth_only=yes -o smtpd_reject_unlisted_recipient=no -o smtpd_client_restrictions=$mua_client_restrictions -o smtpd_helo_restrictions=$mua_helo_restrictions -o smtpd_sender_restrictions=$mua_sender_restrictions -o smtpd_recipient_restrictions= -o smtpd_relay_restrictions=permit_sasl_authenticated,reject -o milter_macro_daemon_name=ORIGINATING smtps inet n - n - - smtpd -o syslog_name=postfix/smtps -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes EOF # 启动Postfix [root@fgedu-mail ~]# systemctl enable postfix --now

Part02-Dovecot配置

2.1 IMAP/POP3服务

# 配置Dovecot
[root@fgedu-mail ~]# cat > /etc/dovecot/dovecot.conf << 'EOF' protocols = imap pop3 listen = *, :: dict { } !include conf.d/*.conf EOF # 配置认证 [root@fgedu-mail ~]# cat > /etc/dovecot/conf.d/10-auth.conf << 'EOF' disable_plaintext_auth = no auth_mechanisms = plain login !include auth-system.conf.ext EOF # 配置邮件存储 [root@fgedu-mail ~]# cat > /etc/dovecot/conf.d/10-mail.conf << 'EOF' mail_location = maildir:~/Maildir namespace inbox { inbox = yes } mail_privileged_group = mail EOF # 配置SSL [root@fgedu-mail ~]# cat > /etc/dovecot/conf.d/10-ssl.conf << 'EOF' ssl = required ssl_cert = /etc/dovecot/conf.d/10-master.conf << 'EOF' service imap-login { inet_listener imap { port = 143 } inet_listener imaps { port = 993 ssl = yes } } service pop3-login { inet_listener pop3 { port = 110 } inet_listener pop3s { port = 995 ssl = yes } } service auth { unix_listener /var/spool/postfix/private/auth { mode = 0666 user = postfix group = postfix } } EOF # 启动Dovecot [root@fgedu-mail ~]# systemctl enable dovecot --now # 创建邮件用户 [root@fgedu-mail ~]# useradd -s /sbin/nologin fgedu [root@fgedu-mail ~]# echo "fgedu:Mail@123" | chpasswd # 测试邮件发送 [root@fgedu-mail ~]# echo "Test email from FGEDU" | mail -s "Test" -r admin@fgedu.net.cn fgedu@fgedu.net.cn

Part03-反垃圾邮件

3.1 SpamAssassin配置

# 安装SpamAssassin
[root@fgedu-mail ~]# yum install -y spamassassin

# 配置SpamAssassin
[root@fgedu-mail ~]# cat > /etc/mail/spamassassin/local.cf << 'EOF' required_hits 5.0 report_safe 0 required_score 5.0 rewrite_header Subject [SPAM] # 白名单 whitelist_from *@fgedu.net.cn # 黑名单 blacklist_from *@spam.com # 自定义规则 header LOCAL_FROM_MISSING From =~ /^$/ describe LOCAL_FROM_MISSING From header is missing score LOCAL_FROM_MISSING 2.0 body LOCAL_HELLO /Hello/ describe LOCAL_HELLO Contains Hello score LOCAL_HELLO 0.5 # Bayes过滤 use_bayes 1 bayes_auto_learn 1 bayes_auto_learn_threshold_nonspam 0.1 bayes_auto_learn_threshold_spam 12.0 # Razor检查 use_razor2 1 # Pyzor检查 use_pyzor 1 EOF # 配置Postfix集成 [root@fgedu-mail ~]# cat >> /etc/postfix/master.cf << 'EOF' spamassassin unix - n n - - pipe user=spamd argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient} EOF [root@fgedu-mail ~]# cat >> /etc/postfix/main.cf << 'EOF' content_filter = spamassassin EOF # 启动SpamAssassin [root@fgedu-mail ~]# systemctl enable spamassassin --now [root@fgedu-mail ~]# postfix reload # 安装ClamAV [root@fgedu-mail ~]# yum install -y clamav clamd [root@fgedu-mail ~]# freshclam [root@fgedu-mail ~]# systemctl enable clamd@scan --now

Part04-邮件监控

4.1 邮件服务监控

# 创建邮件监控脚本
[root@fgedu-mail ~]# cat > /usr/local/bin/mail-monitor.sh << 'EOF' #!/bin/bash # mail-monitor.sh # from:www.itpux.com.qq113257174.wx:itpux-com # web: http://www.fgedu.net.cn echo "=== 邮件服务监控 ===" echo "监控时间: $(date)" echo "" echo "1. 服务状态" echo "Postfix: $(systemctl is-active postfix)" echo "Dovecot: $(systemctl is-active dovecot)" echo "SpamAssassin: $(systemctl is-active spamassassin)" echo "" echo "2. 队列状态" postqueue -p | tail -1 echo "" echo "3. 今日邮件统计" echo "发送: $(grep -c "status=sent" /var/log/maillog 2>/dev/null || echo 0)”
echo “接收: $(grep -c “message-id” /var/log/maillog 2>/dev/null || echo 0)”
echo “垃圾邮件: $(grep -c “identified spam” /var/log/maillog 2>/dev/null || echo 0)”

echo “”
echo “4. 活跃连接”
ss -tuln | grep -E “:(25|110|143|465|587|993|995)”

echo “”
echo “5. 磁盘使用”
du -sh /var/mail
du -sh /home/*/Maildir 2>/dev/null | head -5

echo “”
echo “6.更多视频教程www.fgedu.net.cn 最近错误”
grep -i error /var/log/maillog | tail -5

echo “”
echo “=== 监控完成 ===”
EOF

[root@fgedu-mail ~]# chmod +x /usr/local/bin/mail-monitor.sh

# 配置日志轮转
[root@fgedu-mail ~]# cat > /etc/logrotate.d/maillog << 'EOF' /var/log/maillog { daily rotate 30 compress delaycompress missingok notifempty create 0640 root root postrotate /usr/bin/systemctl reload postfix > /dev/null 2>&1 || true
endscript
}
EOF

# 配置邮件别名
[root@fgedu-mail ~]# cat >> /etc/aliases << 'EOF' postmaster: root abuse: root security: root admin: fgedu support: fgedu EOF [root@fgedu-mail ~]# newaliases

风哥针对邮件服务建议:

  • 配置SPF/DKIM/DMARC记录
  • 启用TLS加密传输
  • 配置反垃圾邮件系统
  • 定期备份邮件数据
  • 监控邮件队列状态

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息