在 CentOS 上监控邮件服务器(如 Postfix / Sendmail / Dovecot / Exim 等),通常可以从系统层、服务层、日志层、队列层、第三方工具几个维度来做。下面给你一套实用可落地方案。
先确认邮件服务类型:
ps -ef | grep -E "postfix|sendmail|exim|dovecot"
常见组合:
systemctl status postfix
systemctl status dovecot
设置开机自启并监控:
systemctl enable postfix
systemctl enable dovecot
#!/bin/bash
systemctl is-active --quiet postfix || echo "Postfix down" | mail -s "Mail Alert" admin@yourdomain.com
可放入 crontab:
* * * * * /root/check_mail.sh
mailq
# 或
postqueue -p
查看队列数量:
mailq | grep -c "^[A-F0-9]"
队列异常暴增通常意味着:
/var/log/maillog
实时查看:
tail -f /var/log/maillog
常见关键词:
status=sent ✅status=deferred ⏳status=bounced ❌relay=none ❌SASL authentication failed ⚠️发现大量 bounced:
grep "status=bounced" /var/log/maillog | wc -l
top
htop
df -h
du -sh /var/spool/mail/*
netstat -an | grep :25 | wc -l
监控项:
node_exporterpostfix_exporteryum install monit
示例监控 Postfix:
check process postfix with pidfile /var/spool/postfix/pid/master.pid
start program = "/usr/sbin/postfix start"
stop program = "/usr/sbin/postfix stop"
if failed port 25 then alert
postconf -n | grep mynetworks
grep "authentication failed" /var/log/maillog
firewall-cmd --add-service=smtp --permanent
firewall-cmd --reload
✅ 必做:
systemctl 服务存活mailq 队列监控/var/log/maillog 错误统计✅ 推荐:
如果你愿意,可以告诉我:
我可以直接给你定制监控脚本或 Zabbix 模板。