tft每日頭條

 > 科技

 > linux服務器管理與配置

linux服務器管理與配置

科技 更新时间:2024-09-07 14:52:27

3.24下午接到客戶反饋,系統出現了大量的sendmail及postdrop進程,導緻系統崩潰。需要協助排查。具體故障截圖及處理過程如下。

客戶提供的截圖:

linux服務器管理與配置(linux服務器大量的sendmail及postdrop進程故障排查)1

linux服務器管理與配置(linux服務器大量的sendmail及postdrop進程故障排查)2

可以看到系統産生了大量的sendmail及postdrop進程,1分鐘産生一個。

通過查看對應進程的父進程确定是crond導緻的

linux服務器管理與配置(linux服務器大量的sendmail及postdrop進程故障排查)3

應急措施 停止crond

service stop crond

殺掉sendmail及postdrop進程

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

同時客戶反饋上午的時候發現/var目錄滿了 然後重啟了主機 把postfix服務給停止了。通過網上查看crond 導緻大量的sendmail進程有相關的案例.

聯系客戶查看crontab是否配置定時任務。結果如下

linux服務器管理與配置(linux服務器大量的sendmail及postdrop進程故障排查)4

系統中存在兩個定時任務,一個是用于nginx日志切割的,一個是用于華三虛拟化agent檢測的。注意上圖的/etc/crontab裡面的mail="root"。

按照網上的解決方案,我先把日志切割的任務添加一下日志輸出重定向。

linux服務器管理與配置(linux服務器大量的sendmail及postdrop進程故障排查)5

然而添加的時候出現設備上面沒有空間的報錯。

查看文件系統使用率正常

linux服務器管理與配置(linux服務器大量的sendmail及postdrop進程故障排查)6

聯想到大量的sendmail可能會産生很多小文件,查看i節點信息,果然i節點滿了

linux服務器管理與配置(linux服務器大量的sendmail及postdrop進程故障排查)7

處理i節點問題

cd /var/spool/postfix/maildrop ls | xargs -n 1000 rm -rf //要批量删,一次1000個,直接rm可能删不成功

再次查看恢複正常

linux服務器管理與配置(linux服務器大量的sendmail及postdrop進程故障排查)8

再次修改contab腳本,正常修改。

linux服務器管理與配置(linux服務器大量的sendmail及postdrop進程故障排查)9

啟動crond服務。經過十幾分鐘的觀察sendmail服務未啟動。

總結:

進程啟動順序:postdrop是由sendmail啟動的,而sendmail又是由crond啟動的。問題成因:crond在執行腳本時會将腳本輸出信息以郵件的形式發送給系統用戶,所以必然要調用sendmail,而sendmail又會調用postdrop發送郵件,但是如果系統的postfix服務沒有正常運行,那麼郵件就會發送不成功,造成sendmail、postdrop、crond進程就無法正常退出,形成大量的僵屍進程

所以根本的原因還是postfix服務被禁用了導緻的。

解決這個問題有兩個辦法:

在crontab末尾加上 >/dev/null 2>&1. 或&> /dev/null 例如*/10 * * * * /home/a.sh >/dev/null 2>&1 另外一種方法是crontab第一行加入,那麼後面執行的crontab腳本就不會發送mail了 MAILTO=""

man 5 contab查看crontab幫助

In addition to LOGNAME, HOME, and SHELL, cron(8) looks at the MAILTO variable if a mail needs to be send as a result of running any commands in that particular crontab. If MAILTO is defined (and non-empty), mail is sent to the specified address. If MAILTO is defined but empty (MAILTO=""), no mail is sent. Otherwise, mail is sent to the owner of the crontab. This option is useful if you decide to use /bin/mail instead of /usr/lib/sendmail as your mailer. Note that /bin/mail does not provide aliasing and UUCP usually does not read its mail. If MAILFROM is defined (and non-empty), it is used as the envelope sender address, otherwise, ``root'' is used。

,

更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!

查看全部

相关科技资讯推荐

热门科技资讯推荐

网友关注

Copyright 2023-2024 - www.tftnews.com All Rights Reserved