zoukankan      html  css  js  c++  java
  • 探讨:crond 引发大量sendmail进程的解决办法

    某服务器账号comm无法登录,说是资源消耗完毕。
    于是用另一个账号登陆到服务器,检查common账号到底启动了哪些dd引起资源耗尽:
    ps -u common
    发现有个 sendmail的启动特别多
    例如:
    common   31446 31377  0 20:20 ?       /usr/sbin/sendmail -FCronDaemon -i -odi -oem -oi -t -f root
    鉴于资源耗尽,留下证据后,先杀掉,保证生产:
     

    复制代码 代码示例:

    ps -ef|grep "/usr/sbin/sendmail"|grep -v grep |awk '{print $2}'|xargs kill

    然后,检查是哪个进程启动了sendmail:
     

    复制代码 代码示例:

    ps -ef|grep 31337

    发现是crond启动了。
    这个进程怎么会调用sendmail呢?
    既然是crond启动的,而之前一直好好的,于是询问最近谁修改了crond。
    经查,有个同事添加了一个crond记录,一分钟运行一次。

    然后,查看sendmail进程:
     

    复制代码 代码示例:

    ps -ef|grep sendmail
     

    果然又有了,而且sendmail是1分钟启动一个。

    看来就是它了,将它从crontab暂停,2分钟过去。
    没有新的sendmail启动,于是将问题就锁定在它身上了。

    也没有想到原因,为啥crond会调用sendmail,google之找到了这样一句
    crond在执行脚本时会将脚本输出信息以邮件的形式发送给crond用户,而环境的postfix没有正常运行,导致邮件发送失败。
    查看maillog,确实有很多错误:
    postfix/postdrop[23110]: warning: mail_queue_enter: create file maildrop/749274.23110: No such file or directory

    解决方法:
    在crontab中第一行增加MAILTO=""发送为空

    如果cron有什么原因需要将命令结果发一封邮件,那么就要看MAILTO这部分了,如果给MAILTO赋值了,并且不是空,那么就会发给这个用户;
    如果是空,MAILTO="",那就不发任何邮件。
    如果没有定义MAILTO,也就是说crontab里面没有写这一行,那么就发给这个crontab的用户

    下面来看下man手册中的解释吧。
    man 5 crontab
        In  addition  to  LOGNAME,  HOME, and SHELL, cron(8) will look at MAILTO if it has any reason to send
     mail as aresult of running commands in "this" crontab.  If MAILTO is defined (and non-empty), mail is 
    sent to  the  userso  named.   If  MAILTO  is defined but empty (MAILTO=""), no mail will be sent.  
    Otherwise mail is sent to the owner of the crontab.  This option is useful if you decide on /bin/mail
     instead of  /usr/lib/sendmail  as  your mailer when you install cron -- /bin/mail doesn′t do aliasing, 
    and UUCP usually doesn′t read its mail. If MAIL-FROM is defined (and non-empty), 
    it will be used as the envelope sender address, otherwise,  ‘‘root’’  will  be used.

    由于我们这个不需要发邮件,于是 在crontab 第一行加上 MAILTO="",到此问题解决了。

    本文标题:探讨:crond 引发大量sendmail进程的解决办法 
    本文URL:http://www.51ou.com/browse/xitongguanli/37981.html 
  • 相关阅读:
    BZOJ1409 : Password
    BZOJ2862 : 分糖果
    BZOJ2093 : [Poi2010]Frog
    BZOJ2506 : calc
    BZOJ3290 : Theresa与数据结构
    BZOJ1397 : Ural 1486 Equal squares
    BZOJ2789 : [Poi2012]Letters
    BZOJ3417 : Poi2013 Tales of seafaring
    BZOJ3251 : 树上三角形
    BZOJ3262 : 陌上花开
  • 原文地址:https://www.cnblogs.com/canphp/p/4030176.html
Copyright © 2011-2022 走看看