歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

Linux進程多導致CPU卡死的問題

一、郵箱收到一堆監控,報警內空大致如下,很明顯是CPU不夠用了,IO也有點問題:主機: bwebser2__10.253.5.198 時間: 2015.11.15 15:25:17狀態: PROBLEM 級別: Warning報警原因: Processor load is too high on bwebser2內容: Processor load (1 min average per core):value=52.53原始事件ID: 30605主機: bwebser2__10.253.5.198時間: 2015.11.18 15:42:23 狀態: PROBLEM級別: Warning 報警原因: Disk I/O is overloaded on bwebser2 內容: CPU iowait time:value=68.7 %原始事件ID: 30812

二、用top查看進程,發現有近2000個進程

[root@bwebser2 ~]# top
top - 10:00:32 up 184 days, 19:55,  2 users,  load average: 49.39, 52.06, 53.04
Tasks: 1826 total,   1 running, 1825 sleeping,   0 stopped,   0 zombie
Cpu(s): 22.5%us,  3.8%sy,  0.0%ni, 31.7%id, 41.3%wa,  0.7%hi,  0.0%si,  0.0%st
Mem:   8058056k total,  7631808k used,   426248k free,   718780k buffers
Swap:        0k total,        0k used,        0k free,   358720k cached

三、猜測可能和sendmail有關,查maillog日志,一直報警:No space left on device

[root@bwebser2 ~]# tail -f  /var/log/maillog     
Nov 19 10:12:15 bwebser2 postfix/postdrop[19470]: warning: mail_queue_enter: create file maildrop/878633.19470: No space left on device
Nov 19 10:12:15 bwebser2 postfix/postdrop[27287]: warning: mail_queue_enter: create file maildrop/900082.27287: No space left on device
Nov 19 10:12:15 bwebser2 postfix/postdrop[12347]: warning: mail_queue_enter: create file maildrop/919377.12347: No space left on device
Nov 19 10:12:15 bwebser2 postfix/postdrop[21222]: warning: mail_queue_enter: create file maildrop/937001.21222: No space left on device
Nov 19 10:12:16 bwebser2 postfix/postdrop[25028]: warning: mail_queue_enter: create file maildrop/956095.25028: No space left on device
Nov 19 10:12:16 bwebser2 postfix/postdrop[28123]: warning: mail_queue_enter: create file maildrop/980022.28123: No space left on device
Nov 19 10:12:16 bwebser2 postfix/postdrop[26680]: warning: mail_queue_enter: create file maildrop/999360.26680: No space left on device

四、用lsof確定sendmail、postdrop進程數量,進程數達到2000多個,為什麼有這麼多呢?

[root@bwebser2 ~]# lsof |grep sendmail |wc -l
24682
[root@bwebser2 ~]# lsof |grep postdrop  |wc -l
24108
五、查看文件索引節點inode,發現空間滿了:
[root@bwebser2 log]# df -i
Filesystem       Inodes   IUsed    IFree IUse% Mounted on
/dev/xvda1      1310720 1310720        0  100% /
tmpfs           1007257       1  1007256    1% /dev/shm
/dev/xvdb1     13107200    6142 13101058    1% /u01

用df -Th命令:
root@cwebser3 statistics]# df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/xvda1     ext4    20G  4.1G   15G  22% /
tmpfs          tmpfs  3.9G     0  3.9G   0% /dev/shm
/dev/xvdb1     ext3   197G   18G  170G  10% /u01

六、通過清除zookeeper監控日志把騰出根的空間

cd /home/zookeeper/monitor 
[root@bwebser2 monitor]# ll
total 8
drwxrwxr-x 163 zookeeper zookeeper 4096 Nov 12 00:16 charts
drwxrwxr-x 167 zookeeper zookeeper 4096 Nov 18 17:31 statistics
[root@bwebser2 monitor]# cd charts
rm -rf *
[root@bwebser2 monitor]# cd ../statistics/
[root@bwebser2 statistics]# rm -rf 201506*
[root@bwebser2 statistics]# rm -rf 201507*
[root@bwebser2 statistics]# rm -rf 201508*
[root@bwebser2 statistics]# rm -rf 201509*
[root@bwebser2 statistics]# rm -rf 201510*

七、殺死所有sendmail和postdrop進程後

[root@bwebser2 ~]#ps -ef|grep sendmail | grep -v grep | awk  '{print "kill -9 " $2}' |sh
[root@bwebser2 ~]#ps -ef|grep postdrop | grep -v grep | awk  '{print "kill -9 " $2}' |sh

八、lsof查看,進程數為0

[root@bwebser2 ~]# lsof |grep sendmail |wc -l
0
[root@bwebser2 ~]# lsof |grep postdrop  |wc -l
0

九、被忽略的/etc/cron.d下的sysstat,修改sysstat,操作如下:

[root@bwebser2 cron.d]#cd /etc/cron.d/
[root@bwebser2 cron.d]# ll
total 12
-rw-r--r--. 1 root root 113 Nov 23  2013 0hourly
-rw-r--r--. 1 root root 108 Apr  7  2014 raid-check
-rw-r--r--. 1 root root 235 Nov 23  2013 sysstat
 
vi sysstat添加&>/dev/null
# run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/lib/sa/sa1 1 1 &>/dev/null
# generate a daily summary of process accounting at 23:53
53 23 * * * root /usr/lib/sa/sa2 -A &>/dev/null  

十、再次用top命令查看進程只有100多個,監控報警消失,問題搞定!

[root@bwebser2 cron.d]# service sendmail restart
sendmail: unrecognized service
[root@cwebser3 cron.d]# top
top - 10:43:12 up 184 days, 20:37,  2 users,  load average: 1.03, 1.54, 14.15
Tasks: 105 total,   1 running, 104 sleeping,   0 stopped,   0 zombie
Cpu(s): 43.4%us,  1.3%sy,  0.0%ni, 47.9%id,  7.0%wa,  0.3%hi,  0.0%si,  0.0%st
Mem:   8058056k total,  6762996k used,  1295060k free,  1422060k buffers
Swap:        0k total,        0k used,        0k free,   381392k cached

 

Copyright © Linux教程網 All Rights Reserved