the5fire

关注Python、Django、Vim、Linux、Web开发、团队管理和互联网--Life is short, we need Python.


512M内存VPS运行wordpress出现"数据库连接错误"

作者:the5fire | 标签:     | 发布:2014-08-29 6:46 a.m. | 阅读量: 10837, 10568

今天同学让帮忙看个网站,wordpress搭的,阿里云的主机512M内存,运行一天之后就无法访问提示:"数据库无法连接"。于是乎花了些时间帮他看看。记录下过程,可能还会有人碰到类似的问题。

总结下折腾的过程,无外乎先查看数据库情况,然后在做判断。发现数据库挂了。手动启动之后网站恢复访问,运行一段时间之后mysql又挂了。

通过top命令看了下系统内存使用率,和哪些系统占用内存最多(top,然后M键),发现十个httpd的进程(Apache的进程),每个占用7.x%的内存。这加起来就70%多了,再加上其他进程。应该是mysql启动之后占内存比其他进程都多,然后超过512M之后被kill掉了。

为了确认猜想,重启mysql之后,对网站进行压测,很快内存占用率上升,mysql阵亡。果然如此。

现在要做的就是对Apache进行优化了,网上查到一个解决访问,限制Apache对内存的占用, 配置到httpd.conf中。

.. code:: python

Timeout 30
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 2
<IfModule prefork.c>
    # number of server processes to start
    # http://httpd.apache.org/docs/2.2/mod/mpm_common.html#startservers
    # 服务器启动时,产生的服务进程
    StartServers       4
    # minimum number of server processes which are kept spare
    # http://httpd.apache.org/docs/2.2/mod/prefork.html#minspareservers
    # 系统空闲态,至少要保留的服务进程数,也就是相当于,饭店里没人吃饭,也要至少站6个服务员等顾客来
    MinSpareServers    4
    # maximum number of server processes which are kept spare
    # http://httpd.apache.org/docs/2.2/mod/prefork.html#maxspareservers
    # 系统空闲态,至多保留的服务进程数,也就是相当于,饭店里要是没有顾客,数一数站着没事的服务员,多于10个的话,就是让他们放假回家.
    MaxSpareServers    8
    # highest possible MaxClients setting for the lifetime of the Apache process.
    # http://httpd.apache.org/docs/2.2/mod/mpm_common.html#serverlimit
    # 服务器允许配置的进程数上限,设置了MaxClients最大允许配置的数值.必须重启服务器才生效的值.
    ServerLimit       10
    # maximum number of server processes allowed to start
    # http://httpd.apache.org/docs/2.2/mod/mpm_common.html#maxclients
    # 服务器允许连接的进程数上限,也就是饭店里正常情况下最大允许进入的人数.此值不需要重启服务器即可修改生效,但不能超过ServerLimit,及时配置超过,也只能最大运行ServerLimit个进程.
    MaxClients        10
    # maximum number of requests a server process serves
    # http://httpd.apache.org/docs/2.2/mod/mpm_common.html#maxrequestsperchild
    MaxRequestsPerChild  40
</IfModule>

贴进去,重启httpd,压力测试,没挂。

参考

http://linxucn.blog.51cto.com/1360306/736322

- from the5fire.com
----EOF-----

微信公众号:Python程序员杂谈


其他分类: