crond 引发大量 sendmail 进程的解决办法

#编程技术 2021-01-19 16:34:00 | 全文 586 字,阅读约需 2 分钟 | 加载中... 次浏览

👋 相关阅读


发现问题

这两天看到几台服务器比较异常,平常流量跑满,突然就没有了流量,TCP 连接也没了。于是登录上服务器查看,首先想重启 nginx 服务,结果报错,大致意思就是磁盘空间已满。通过 df -h 命令查看,发现各个分区还有很充足的空间,然后 df -i 一看,发现分区 inode 已经满了。

定位问题

第一反应是 /var 目录下的文件导致,于是用下面脚本找出 /var 下各个目录文件数量,逐步定位到 /var/spool/postfix/maildrop

#!/bin/sh
find /var/ -maxdepth 1 -type d | while read dir; do 
    count=$(find "$dir" -type f | wc -l)
    echo "$dir : $count"
done

找到目标,首要就是先杀掉这里面的大量文件,三十多万文件。采用 rsync 同步清除,效率比较快。

在其他分区创建空目录:

// 杀死所有 sendmail 和 postdrop 进程
ps -e | grep sendmail | cut -d ' ' -f2 | xargs kill
ps -e | grep postdrop| cut -d ' ' -f2 | xargs kill

mkdir -p /home/a.test
rsync -av --delete /home/a.test/  /var/spool/postfix/maildrop/

查看其他错误日志,发现都是 crond 引发的 sendmail

du -sh 查看找到了一个巨大的文件 /var/log/mailog 。head、tail 查看内容,发现全是同样的内容行,如下:

May 2 5:29:23 lcha2 postfix/postdrop[1443]: warning: mail_queue_enter: create file maildrop/383480.1443: No such file or directory
May 2 5:29:23 lcha2 postfix/postdrop[1269]: warning: mail_queue_enter: create file maildrop/330426.1269: No such file or directory
May 2 5:29:23 lcha2 postfix/postdrop[1439]: warning: mail_queue_enter: create file maildrop/357169.1439: No such file or directory
May 2 5:29:23 lcha2 postfix/postdrop[1654]: warning: mail_queue_enter: create file maildrop/984222.1654: No such file or directory

解决方法:

1、 修改邮件日志输出条件

vim /etc/rsyslog.conf

找到 mail.*

改成 mail.err

2、 在 crontab 中第一行增加 MAILTO="" 发送为空

MAILTO=""

3、将 /etc/crontab 中的 MAILTO 改为 ""

4、将 /etc/postfix/main.cf 配置文件中,inet_protocols = all 改为 inet_protocols = ipv4

5、 crond 执行的命令最后加上 &> /dev/null

via

crond 引发大量sendmail进程的解决办法 - Yun维攻城狮 http://www.89cool.com/411.html Crontab导致Linux文件描述符枯竭-king_wangheng-ChinaUnix博客 http://blog.chinaunix.net/uid-26896862-id-3809084.html

Edit | Last updated on 2024-04-08 15:48:44




×