监控 Debian 邮件服务器,通常要从 服务状态、日志、队列、资源、安全、性能指标 等多个层面来做。下面给你一套从基础到进阶的完整监控方案,适用于常见的 Debian + Postfix / Exim + Dovecot 邮件服务器。
先明确你用的是哪些组件(常见组合):
systemctl status postfix
systemctl status dovecot
设置开机自启:
systemctl enable postfix dovecot
使用 systemd + 监控脚本或 monit。
apt install monit
编辑:
/etc/monit/conf.d/postfix
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 not exist then restart
tail -f /var/log/mail.log
常见错误:
connection refusedrelay access deniedbouncedrejected/var/log/mail.log # 主日志
/var/log/mail.err # 错误
/var/log/mail.info
使用 logwatch 或 fail2ban:
apt install logwatch fail2ban
mailq
postqueue -p
查看队列数量:
mailq | grep -c "^[A-F0-9]"
⚠️ 队列突然暴涨 = 被当成垃圾邮件中继
top
htop
vmstat 1
iostat -x 1
df -h
du -sh /var/mail/*
du -sh /var/spool/mail/*
df -i
| 项目 | 说明 |
|---|---|
| SMTP 25/465/587 | 是否可连接 |
| IMAP/POP3 | 用户能否收信 |
| 邮件队列长度 | 防止被滥用 |
| 发信成功率 | 减少退信 |
| 垃圾邮件比例 | 防止被封 |
| 登录失败次数 | 防暴力破解 |
apt install prometheus-node-exporter
用于监控 Postfix 状态。
echo "test" | mail -s "test" user@example.com
telnet localhost 25
或:
nc -zv localhost 25
grep "Failed" /var/log/mail.log
fail2ban-client status dovecot
fail2ban-client status postfix
✅ 小型服务器
✅ 中型/企业级
#!/bin/bash
QUEUE=$(mailq | grep -c "^[A-F0-9]")
if [ "$QUEUE" -gt 100 ]; then
echo "邮件队列异常:$QUEUE" | mail -s "邮件服务器告警" admin@example.com
fi
你可以告诉我:
我可以直接给你 定制监控脚本 + Grafana 模板。