今天一位同事說一個服務器common賬號登陸不進去,說是資源耗盡,要我幫忙檢查一下
我用另一個賬號登陸到服務器,首先我想看看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 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=""
觀察了兩分鍾,問題解決。
