Apache2进程在512MB VPS上占用过多的内存

我正在运行一个具有512MB内存的Ubuntu VPS。 它只是开发服务器,所以几乎没有stream量。 尽pipe如此,我不时得到内存耗尽的消息,我的整个内存都被用完了。 我试图在SF上浏览各种类似的问题,但是却无法真正了解没有stream量的服务器正在占用内存的情况。 以下是顶部的输出:

ps aux的输出为:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.3 23572 1684 ? Ss Apr11 0:03 init root 1177 0.0 0.1 18888 1028 ? Ss Apr11 0:01 cron mysql 1189 0.0 5.6 258344 29680 ? Ssl Apr11 1:04 /usr/sbin/mysqld syslog 1202 0.0 0.1 12536 788 ? Ss Apr11 0:01 /sbin/syslogd -u syslog root 1268 0.0 0.5 49424 2684 ? Ss Apr11 0:00 /usr/sbin/sshd -D root 1305 0.0 0.4 66168 2560 ? Ss Apr11 0:15 sendmail: MTA: accepting connections root 8062 0.0 0.6 70796 3408 ? Ss 10:50 0:00 sshd: root@pts/0 root 8074 0.0 0.4 18160 2224 pts/0 Ss+ 10:52 0:00 -bash root 8134 0.0 0.6 70796 3428 ? Ss 11:37 0:00 sshd: root@pts/1 root 8146 0.0 0.4 18160 2232 pts/1 Ss 11:37 0:00 -bash root 9337 0.0 2.8 270140 15176 ? Ss 11:49 0:00 /usr/sbin/apache2 -k start www-data 9341 0.0 1.9 270272 10276 ? S 11:49 0:00 /usr/sbin/apache2 -k start root 9346 0.0 0.2 15064 1136 pts/1 R+ 11:56 0:00 ps aux bind 19665 0.0 2.5 142836 13624 ? Ssl Apr25 0:00 /usr/sbin/named -u bind 

并输出顶部:

 Tasks: 18 total, 1 running, 17 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 524288k total, 301000k used, 223288k free, 0k buffers Swap: 0k total, 0k used, 0k free, 0k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 15 0 23572 1684 1332 S 0 0.3 0:03.66 init 1177 root 18 0 18888 1028 796 S 0 0.2 0:01.17 cron 1189 mysql 18 0 252m 28m 7944 S 0 5.7 1:04.58 mysqld 1202 syslog 15 0 12536 788 592 S 0 0.2 0:01.95 syslogd 1268 root 18 0 49424 2684 2120 S 0 0.5 0:00.12 sshd 1305 root 18 0 66168 2560 880 S 0 0.5 0:15.99 sendmail-mta 8062 root 19 0 70796 3408 2656 S 0 0.7 0:00.04 sshd 8074 root 15 0 18160 2224 1548 S 0 0.4 0:00.00 bash 8134 root 15 0 70796 3428 2656 S 0 0.7 0:00.10 sshd 8146 root 15 0 18160 2232 1556 S 0 0.4 0:00.04 bash 9337 root 18 0 263m 14m 5736 S 0 2.9 0:00.08 apache2 9341 www-data 15 0 263m 10m 816 S 0 2.0 0:00.00 apache2 9397 root 18 0 70796 3408 2656 S 0 0.7 0:00.02 sshd 9409 root 15 0 12560 928 748 S 0 0.2 0:00.00 sftp-server 9410 root 15 0 70796 3428 2656 S 0 0.7 0:00.01 sshd 9422 root 18 0 12564 872 668 S 0 0.2 0:00.00 sftp-server 9425 root 15 0 19176 1188 932 R 0 0.2 0:00.00 top 19665 bind 18 0 139m 13m 2152 S 0 2.6 0:00.07 named 

Apache2 + PHP + mySQL总是使用大量的内存,即使只有less量的连接,开箱即用。 你必须调整它。 您需要限制Apache进程的数量(假设您使用的是mpm_prefork),并且需要通过调整各种caching和其他元素来减lessmysql的内存占用。

对于未使用的Apache2服务器(prefork mpm)5-10个并发连接,使用PHP和mysql,512MB的内存,可能会导致内存不足。

此外,您的服务器正在运行其他进程,如bind和sendmail,这些进程都有自己的内存要求。

你将不得不使用networking上的各种指南来调整它,以及在ServerFault上的其他类似的问题。

值得一提的是,这与每天的总点击量无关,而与networking服务器的并发会话无关。 每天20次击中同一秒内会杀死你的服务器,每天20次击中1次命中不会。

这样说 – 如果每个Apache2进程使用40MB的内存(并且可以轻松地使用PHP5和其他模块),那么在服务器仅为Web服务器使用400MB之前,您可以容忍大约9或10个并发连接。 这一切都留下115MB的一切。