在 Ubuntu 上“监控邮件服务”通常取决于你使用的是哪种邮件服务(如 Postfix、Exim、Sendmail、Dovecot、或云邮箱中继)。下面我按常见场景 + 实用方法给你一个较完整的指南。
ps aux | grep -E 'postfix|exim|sendmail|dovecot'
或
systemctl list-units --type=service | grep -E 'mail|postfix|exim|dovecot'
常见组合:
systemctl status postfix
systemctl status dovecot
开机自启检查:
systemctl is-enabled postfix
mailq
# 或
postqueue -p
清空队列(谨慎):
postsuper -d ALL
Ubuntu 通常使用 rsyslog + journald
tail -f /var/log/mail.log
或
journalctl -u postfix -f
常见日志位置:
/var/log/mail.log/var/log/mail.errss -lntp | grep -E '25|465|587|110|143|993|995'
安装:
sudo apt install monit
示例 /etc/monit/conf.d/mail:
check process postfix with pidfile /var/spool/postfix/pid/master.pid
start program = "/usr/sbin/service postfix start"
stop program = "/usr/sbin/service postfix stop"
if failed port 25 protocol smtp then alert
启动:
systemctl restart monit
systemctl enable --now postfix
自动重启:
[Service]
Restart=always
modules:
smtp:
prober: tcp
tcp:
query_response:
- expect: "220"
grep 'status=sent' /var/log/mail.log
grep 'status=bounced' /var/log/mail.log
echo "test" | mail -s "test" you@example.com
grep 'relay' /var/log/mail.log
grep 'auth failed' /var/log/mail.log
可配合 fail2ban:
apt install fail2ban
apt install mailgraph
访问:
http://server/mailgraph
| 需求 | 推荐 |
|---|---|
| 个人/小服务器 | tail + mailq + Monit |
| 企业 | Zabbix / Prometheus |
| 安全 | fail2ban + 日志监控 |
如果你愿意,可以告诉我:
我可以直接帮你写 监控脚本或配置文件。