大约 1 天后,我就无法访问我的 VPS(Centos7),除非我重启服务器

大约 1 天后,我就无法访问我的 VPS(Centos7),除非我重启服务器

我有一个 CentOS 7 VPS,安装了 Webmin 和 Virtualmin。我在这个服务器上有多个域以及邮件服务器(Postfix、Dovecot)。有时我无法访问它(无论是从 webmin 使用 IP 地址还是 SSH),直到我从提供商面板重新启动机器。我如何检测问题?我必须查看哪些日志?

以下是“grep -i 'killed process' /var/log/messages”的输出

Oct  2 13:08:32 server kernel: Killed process 2840 (mysqld) total-vm:1641792kB, anon-rss:20564kB, file-rss:0kB
Oct  3 04:24:09 server kernel: Killed process 2874 (mysqld) total-vm:1637124kB, anon-rss:11628kB, file-rss:0kB
Oct  3 05:16:05 server kernel: Killed process 26933 (sh) total-vm:11636kB, anon-rss:4kB, file-rss:140kB
Oct  3 05:16:05 server kernel: Killed process 26884 (/usr/libexec/we) total-vm:165912kB, anon-rss:28kB, file-rss:132kB
Oct  3 05:16:05 server kernel: Killed process 26753 (/usr/libexec/we) total-vm:161776kB, anon-rss:80kB, file-rss:16kB
Oct  3 05:16:05 server kernel: Killed process 26852 (/usr/libexec/we) total-vm:132660kB, anon-rss:2476kB, file-rss:12kB
Oct  3 05:16:05 server kernel: Killed process 26903 (/usr/libexec/we) total-vm:132656kB, anon-rss:1964kB, file-rss:12kB
Oct  3 05:16:05 server kernel: Killed process 26715 (php-cgi) total-vm:486184kB, anon-rss:5772kB, file-rss:136kB
Oct  3 05:16:05 server kernel: Killed process 26953 (sh) total-vm:11636kB, anon-rss:0kB, file-rss:4kB
Oct  3 05:16:05 server kernel: Killed process 26749 (/usr/libexec/we) total-vm:113144kB, anon-rss:1444kB, file-rss:148kB
Oct  3 05:16:05 server kernel: Killed process 26954 (sh) total-vm:11636kB, anon-rss:4kB, file-rss:0kB
Oct  3 05:16:05 server kernel: Killed process 26795 (/usr/libexec/we) total-vm:113144kB, anon-rss:1132kB, file-rss:0kB
Oct  3 05:16:05 server kernel: Killed process 27303 (mysqld) total-vm:288396kB, anon-rss:9340kB, file-rss:0kB
Oct  3 05:16:05 server kernel: Killed process 27109 (php-cgi) total-vm:453836kB, anon-rss:2144kB, file-rss:20488kB
Oct  3 05:16:05 server kernel: Killed process 27111 (php-cgi) total-vm:453836kB, anon-rss:2308kB, file-rss:20000kB
Oct  3 05:16:05 server kernel: Killed process 26851 (/usr/libexec/we) total-vm:105188kB, anon-rss:2620kB, file-rss:4kB
Oct  3 05:16:05 server kernel: Killed process 26898 (/usr/libexec/we) total-vm:105188kB, anon-rss:2660kB, file-rss:44kB
Oct  3 05:34:26 server kernel: Killed process 27190 (php-cgi) total-vm:453836kB, anon-rss:2160kB, file-rss:20624kB
Oct  3 05:57:53 server kernel: Killed process 27186 (php-cgi) total-vm:453836kB, anon-rss:2324kB, file-rss:20280kB
Oct  3 06:00:46 server kernel: Killed process 27180 (php-cgi) total-vm:453836kB, anon-rss:2520kB, file-rss:20312kB
Oct  3 06:02:00 server kernel: Killed process 27187 (php-cgi) total-vm:453836kB, anon-rss:2240kB, file-rss:20076kB
Oct  3 06:04:16 server kernel: Killed process 2889 (named) total-vm:245060kB, anon-rss:512kB, file-rss:0kB
Oct  3 06:11:19 server kernel: Killed process 26709 (php-cgi) total-vm:471000kB, anon-rss:2228kB, file-rss:380kB
Oct  3 06:12:28 server kernel: Killed process 27308 (/usr/libexec/we) total-vm:96044kB, anon-rss:6292kB, file-rss:528kB
Oct  3 06:12:48 server kernel: Killed process 26788 (php-cgi) total-vm:464152kB, anon-rss:1852kB, file-rss:908kB
Oct  3 06:57:17 server kernel: Killed process 27465 (/usr/libexec/we) total-vm:102616kB, anon-rss:5608kB, file-rss:360kB
Oct  3 07:32:00 server kernel: Killed process 27457 (/usr/libexec/we) total-vm:102620kB, anon-rss:5080kB, file-rss:380kB
Oct  3 07:55:06 server kernel: Killed process 27474 (/usr/libexec/we) total-vm:102616kB, anon-rss:5156kB, file-rss:180kB

答案1

首先检查内存占用情况。您的某些服务可能会泄漏内存,因此内存消耗可能会随着时间的推移而增加。

如果你没有安装 sar,请进行调整。这里有一个非常好的指南:

http://www.thegeekstuff.com/2011/03/sar-examples/?utm_source=feedburner

答案2

看来你有内存泄漏。首先检查你的日志。

grep -i 'killed process' /var/log/messages

然后你可以尝试这个技巧来找出哪个进程占用了你的内存。将此命令添加为 crontab 任务:

ps aux | awk '{mem[$11]+=int($6/1024)}; {cpuper[$11]+=$3};{memper[$11]+=$4}; END {for (i in mem) {print cpuper[i]"% ",memper[i]"% ",mem[i]" MB ",i}}' | sort -k3nr | head -n 5 >> /tmp/memoryleak.log

现在您可以检查 /var/log/memoryleak.log

答案3

除了 sar 之外,您还可以安装在顶上并为其配置日志以查找导致 CPU/RAM 使用率过高的确切进程。

相关内容