我的SMTP服务为什么挂了

  1. 1. 背景
  2. 2. 问题排查
  3. 3. 事情的真相

背景

今天打开Mailer的邮箱,发现很久以前给人回复的邮件静静地躺在发送失败的草稿箱里。打开发送,提示输入邮箱密码却怎么也发不出去。

还好我要回复的只是帮人内推的简历,也不知道发我简历的那位哥们会不会恨我。
要是一封情书可能你就真的直到别人快结婚了也不知道自己当年为什么被无视了是吧。

当然说到底,发送邮件有问题肯定是要去修复的。谁让我自架邮件服务器自找麻烦呢。
(简单算一笔帐的话,这个邮箱价值不菲。不仅包含每年域名的更新费7000大洋,还包括每个月的服务器费用1000大洋。)

问题排查

首先得去找验证失败的Log。

1
tailf /var/log/mail.log

试着去登陆等待后台滚动出log来。

1
2
3
Aug  1 23:39:22 bocchi postfix/smtpd[17310]: warning: SASL authentication failure: cannot connect to saslauthd server: No such file or directory
Aug 1 23:39:22 bocchi postfix/smtpd[17310]: warning: SASL authentication failure: Password verification failed
Aug 1 23:39:22 bocchi postfix/smtpd[17310]: warning: xxxxx[xxxx.xxxx.xxxx.xxxx]: SASL PLAIN authentication failed: generic failure

Postfix 验证的时候使用到了Saslauthd。看问题应该是Postfix找不到SASL的进程文件目录。

那么,Saslauthd在跑吗?

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo systemctl status saslauthd

● saslauthd.service - LSB: saslauthd startup script
Loaded: loaded (/etc/init.d/saslauthd; bad; vendor preset: enabled)
Active: active (running) since Mon 2018-12-03 13:22:36 JST; 7 months 28 days ago
Docs: man:systemd-sysv-generator(8)
Process: 999 ExecStart=/etc/init.d/saslauthd start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/saslauthd.service
├─1110 /usr/sbin/saslauthd -a pam -c -m /var/spool/postfix/var/run/saslauthd -n 5
├─1111 /usr/sbin/saslauthd -a pam -c -m /var/spool/postfix/var/run/saslauthd -n 5
├─1112 /usr/sbin/saslauthd -a pam -c -m /var/spool/postfix/var/run/saslauthd -n 5
├─1113 /usr/sbin/saslauthd -a pam -c -m /var/spool/postfix/var/run/saslauthd -n 5
└─1114 /usr/sbin/saslauthd -a pam -c -m /var/spool/postfix/var/run/saslauthd -n 5

好像也没啥问题。至少,我敢确定以前我是可以好好发送邮件的。

谷歌了一下类似问题,貌似可以归结到postfix在chroot下运行的时候,会去寻找/var/spool/postfix/var/run/saslauthd。而在非chroot的情况下会去寻找/var/run/saslauthd

于是去查看postfix的config。

1
2
smtp inet n - y - - smtpd
`

y代表chroot模式。是我眼花了吗? 那岂不是没有任何问题,并且/var/spool/postfix/var/run/saslauthd 也是存在的。

抱着死马当活马医的心态,建立一下从/var/run/saslauthd/var/spool/postfix/var/run/saslauthd的symlink。

再试着发送邮件。”刷~”地一声,如同十年的便秘一样瞬间发送成功了。

继续谷歌,看到很多人抱怨说postfix不管怎么配置chroot总是默认不使用,于是我也懒得追究了。

事情的真相

从一开始配置postfix的时候,应该是抄了哪边的manual。于是神使鬼差使用了ln -s /var/spool/postfix/var/run/saslauthd /var/run/saslauthd

然而,现在使用的服务器的运营商中间因为机房迁移断电重启过一次,导致我的sysmlink失效了。

啊sysmlink重启还能失效? 对的,因为这个目录是/var/run。。。

最近我又收到服务器运营商的maint邮件说要有宕机重启了。这次我应该知道怎么做了。

如果你觉得本文对你有帮助,请给我点赞助。