服务器的内存几乎占用了8GB

最近,我们的服务器面对内存的问题。 从几周前开始,我们的服务器加载非常慢。 访问电子邮件和网站确实需要很长时间。 然后我们要求服务器技术支持为我们重新启动服务器。 重启后,事情恢复正常。 我们认为是时候升级内存了。 我们的服务器最初只有2GB内存,因此我们将其升级到8GB。

我们认为问题解决了。 但是,升级内存后,内存使用量不断增加。 它总是达到最大使用量(例如从7.8 GB内存中免费获得456.5 MB)。 第二天,服务器完全closures,我们不得不要求技术支持再次重新启动服务器。 每当我们面对问题,我们都要求支持人员为我们重新启动服务器。 据支持人员介绍,如果他们的SQL访问,内存将恢复正常。 但是,如果他们再一次,记忆会再次变得更高。 所以,他们怀疑问题是与SQL查询。

我想问,是否真的是SQL查询给出的问题? 或者这是硬件问题? 如果是SQL,我怎么知道哪种查询占用了这么大的内存呢? 我如何检查它? 我们的服务器正在运行在下面的细节:

OS: Linux 2.6.18 CPU: GenuineIntel, Intel(R)Xeon(R)CPU W3550 @ 3.07GHz Average Load: 808.18;674.21;587.18 database records: 421,031 with 58 tables 

查询统计,我可以从PHPMyAdmin提供:

 select 314 k 11.98 k 66.37% set option 34 k 1,296.59 7.18% show fields 19 k 712.00 3.94% update 16 k 620.61 3.44% alter table 16 k 610.32 3.38% change db 15 k 569.08 3.15% insert 15 k 560.20 3.10% show variables 11 k 434.01 2.40% show tables 9,752 371.66 2.06% begin 7,172 273.33 1.51% 

表演“顶”的结果:

 top - 15:20:07 up 1 day, 6:13, 1 user, load average: 497.30, 512.17, 542.15 Tasks: 7743 total, 5 running, 7738 sleeping, 0 stopped, 0 zombie Cpu(s): 23.9%us, 50.9%sy, 0.1%ni, 25.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 8173372k total, 8048380k used, 124992k free, 1816952k buffers Swap: 2096376k total, 216k used, 2096160k free, 533876k cached 

我希望有人能够给我一些build议,因为我面临这个问题已经有一段时间了,我没有人可以请求指导。 先谢谢你。

更新:dmesg

 CPU5: Temperature above threshold, cpu clock throttled CPU7: Temperature/speed normal CPU2: Temperature/speed normal CPU6: Temperature/speed normal CPU1: Temperature above threshold, cpu clock throttled CPU3: Temperature/speed normal CPU0: Temperature/speed normal CPU4: Temperature/speed normal CPU6: Temperature/speed normal CPU5: Temperature/speed normal CPU1: Temperature/speed normal CPU2: Temperature/speed normal CPU4: Temperature/speed normal CPU7: Temperature/speed normal CPU0: Temperature/speed normal CPU3: Temperature/speed normal brute[19592]: segfault at 0000000000000028 rip 00000000080a592f rsp 00000000ffae3a28 error 6 brute[19539]: segfault at 0000000000000028 rip 00000000080a592f rsp 00000000ffae3a28 error 6 CPU2: Temperature/speed normal CPU4: Temperature/speed normal CPU7: Temperature/speed normal CPU1: Temperature/speed normal CPU5: Temperature/speed normal CPU3: Temperature/speed normal CPU6: Temperature/speed normal CPU0: Temperature/speed normal CPU0: Temperature/speed normal CPU7: Temperature/speed normal CPU6: Temperature/speed normal CPU1: Temperature/speed normal CPU2: Temperature/speed normal CPU3: Temperature/speed normal CPU5: Temperature/speed normal CPU4: Temperature/speed normal brute[21368]: segfault at 0000000000000000 rip 0000000008048f03 rsp 00000000ffb82db0 error 4 

今天的TOP成绩:

 top - 10:42:47 up 3 days, 1:35, 1 user, load average: 4.35, 4.53, 4.59 Tasks: 187 total, 5 running, 182 sleeping, 0 stopped, 0 zombie Cpu(s): 12.7%us, 38.5%sy, 0.0%ni, 48.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 8173372k total, 7800156k used, 373216k free, 1653768k buffers Swap: 2096376k total, 216k used, 2096160k free, 2723732k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 27913 consulti 25 0 31096 3700 1172 R 100.2 0.0 1484:40 perl 27916 consulti 25 0 31096 3732 1204 R 100.2 0.0 1051:59 perl 28213 consulti 25 0 31096 3736 1204 R 100.2 0.0 1073:30 perl 28210 consulti 23 0 31096 3740 1204 S 86.9 0.0 1016:23 perl 3205 mysql 15 0 333m 55m 5416 S 13.6 0.7 143:36.73 mysqld 14616 apache 15 0 333m 33m 6056 S 4.7 0.4 1:02.12 httpd 25104 consulti 18 0 31096 3732 1204 R 4.7 0.0 486:12.74 perl 2702 root 15 0 12744 1148 808 R 0.3 0.0 0:00.01 top 1 root 15 0 10352 696 588 S 0.0 0.0 0:01.62 init 2 root RT -5 0 0 0 S 0.0 0.0 0:00.07 migration/0 3 root 34 19 0 0 0 S 0.0 0.0 0:00.07 ksoftirqd/0 4 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0 5 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/1 6 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/1 7 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/1 8 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/2 9 root 34 19 0 0 0 S 0.0 0.0 0:00.02 ksoftirqd/2 10 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/2 11 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/3 12 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/3 13 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/3 14 root RT -5 0 0 0 S 0.0 0.0 0:00.05 migration/4 15 root 34 19 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/4 16 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/4 17 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/5 

首先,就像评论中的其他一些人一样,我非常关心minerdbrute程序。 一个小小的Google侦探工作表明,这些名字分别与比特币挖掘和自动化networkingstream量生成 (如:DDoS攻击中的一个节点)相关联,表明其他人可能正在使用您的服务器用于自己的目的。

快速解决这个问题(并且请尽快修复),而且您还可以通过一些小的数据库调整来改善问题。 鉴于RandomSeed发布的分析 ,你可能有没有使用内存,而是等待在磁盘上,并注意到你添加内存到服务器没有评论任何其他的变化,我怀疑你的MySQL缓冲池太小了。

这归结于数据库服务器性能调整101:磁盘速度慢,内存快。 数据库喜欢预加载或缓冲内存中的数据和索引,以减less对较慢硬盘驱动器的需求。 MySQL有一些configuration设置来控制允许这样caching多less数据。 如果向服务器添加内存,但不要更改这些MySQL设置,则可以通过确保其他(非MySQL)进程具有足够的内存来帮助一点,但这对核心数据库的性能无能为力; 你还需要告诉MySQL你添加的新内存。

那么,该怎么做? 在MySQL的情况下有点棘手,因为MySQL支持多个存储引擎。 你可能使用的是InnoDB,但也可能有MyISAM,或者甚至是用于不同表格的两者的混合。 不幸的是,在不知道哪些表使用什么存储引擎的情况下,以及(如果混合使用)查询大小和容量,很难准确地build议如何更改MySQLconfiguration。

你的问题不是内存限制(不再是):

  • 你有大约2.5 GB的RAM“可用”(124992k免费+ 1816952kcaching+ 533876kcaching)
  • 你的交换很难使用(使用216k)

不过,升级到8GB之前可能并非如此。

现在可能是I / O绑定的,MySQL可能是罪魁祸首::

  • 平均负荷很高(平均负荷:497.30,512.17,542.15)
  • 58分钟的CPU时间(时间57:59)与1天的系统正常运行时间(运行1天,6:13)

看似CPU密集型查询的最常见原因是I / O等待 (即从磁盘读取数据) 很长一段时间 。 这样的查询通常缺乏poper索引和/或拉太多的数据。

现在你需要确定这些查询是什么。 一个好的起点是监视它们的执行时间 。

从你的描述我认为你的系统正在交换。 您可能需要减less/etc/my.cnf中configuration的一些内存分配

您可以通过运行来查看哪些进程正在使用物理内存:

 ps aux --sort=-rss|head -10