V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
guoqiao
V2EX  ›  程序员

部署在阿里云上的wordpress站点时不时会出现数据库连接错误

  •  1
     
  •   guoqiao · 2013-08-06 12:20:57 +08:00 · 10822 次点击
    这是一个创建于 3910 天前的主题,其中的信息可能已经有所发展或是发生改变。
    http://iottech.com.cn/
    首先密码什么的肯定不会错,因为大部分时候是正常的.
    但是每隔2-3天,就会出现数据库连接错误.
    登上去检查,发现mysql服务停止了,开启服务后恢复正常.

    目前不知道是什么原因会时不时导致mysql服务挂掉.
    貌似有几位同学跟我有一样的问题:
    http://bbs.aliyun.com/simple/?t6251.html
    http://bbs.aliyun.com/simple/?t123803.html

    那个什么
    define('WP_ALLOW_REPAIR', true);
    也加了,无济于事.

    这个是公司网站,近期在做推广,时不时挂掉问题很严重啊.客户已经反馈过几次了.
    有没有达人能给小弟一点提示?
    28 条回复    2014-10-30 23:56:23 +08:00
    humiaozuzu
        1
    humiaozuzu  
       2013-08-06 12:27:20 +08:00
    - 主机的配置多少
    - 贴一下mysql的error log
    master
        2
    master  
       2013-08-06 12:33:10 +08:00
    WP信息展示的话,建议装下WP Super Cache,这样推广访问的人多的话,也能应付。
    至于MySQL挂掉的问题,还是贴一下日志吧。
    iZr
        3
    iZr  
       2013-08-06 12:44:15 +08:00   ❤️ 1
    Page Caching using disk: enhanced
    Database Caching using disk
    Object Caching 899/1101 objects using disk
    楼主你要逆天么?全用 disk 做缓存,阿里云的 disk 那是慢得一塌糊涂啊......

    建议用 W3 Total Cache 的memcached
    cxh116
        4
    cxh116  
       2013-08-06 12:46:15 +08:00
    如果是512m内存的linux机器,看看你们的/var/log/kern.log 日志,查找是不是因为内存不够而导致mysql进程被kill.
    如果是,加机器内存,或加swap file

    日志示例
    Aug 5 16:55:38 judgementmace kernel: [104957.959991] Out of memory: Kill process 14134 (bundle) score 302 or sacrifice child
    Aug 5 16:55:38 judgementmace kernel: [104957.960071] Killed process 14134 (bundle) total-vm:223712kB, anon-rss:151136kB, file-rss:312kB
    iZr
        5
    iZr  
       2013-08-06 12:47:07 +08:00
    另外:图片,js,css,html 使用七牛做 cdn 加速(国内的 cdn最好不要用,比如哪个是什么云,你懂的).
    wordpress 插件在 我爱水煮鱼:http://blog.wpjam.com/project/wpjam-qiniutek/
    guoqiao
        6
    guoqiao  
    OP
       2013-08-06 14:31:45 +08:00
    @humiaozuzu
    内存大小:512MB
    系统名称:Ubuntu 12.04 64位

    /var/log/mysql.err以及mysql.log 内容都为空

    不过在kern.log里倒是发现了一点问题:

    cat /var/log/kern.log | grep mysql:

    Aug 5 11:59:46 AY1210311012137b74305 kernel: [6624574.875628] Out of memory: Kill process 9321 (mysqld) score 107 or sacrifice child
    Aug 5 11:59:46 AY1210311012137b74305 kernel: [6624574.877330] Killed process 9321 (mysqld) total-vm:887172kB, anon-rss:53508kB, file-rss:0kB
    Aug 5 11:59:46 AY1210311012137b74305 kernel: [6624575.008973] init: mysql main process (9321) killed by KILL signal
    Aug 5 11:59:46 AY1210311012137b74305 kernel: [6624575.009003] init: mysql main process ended, respawning
    Aug 5 11:59:46 AY1210311012137b74305 kernel: [6624575.731638] type=1400 audit(1375675186.838:67): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=10834 comm="apparmor_parser"
    Aug 5 11:59:47 AY1210311012137b74305 kernel: [6624576.468831] init: mysql main process (10838) terminated with status 1
    Aug 5 11:59:47 AY1210311012137b74305 kernel: [6624576.468857] init: mysql main process ended, respawning
    Aug 5 11:59:48 AY1210311012137b74305 kernel: [6624577.229334] init: mysql post-start process (10839) terminated with status 1
    Aug 5 11:59:48 AY1210311012137b74305 kernel: [6624577.282343] type=1400 audit(1375675188.390:68): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=10862 comm="apparmor_parser"
    Aug 5 11:59:48 AY1210311012137b74305 kernel: [6624577.358414] init: mysql main process (10866) terminated with status 1
    Aug 5 11:59:48 AY1210311012137b74305 kernel: [6624577.358453] init: mysql respawning too fast, stopped
    Aug 6 11:23:15 AY1210311012137b74305 kernel: [6708784.129980] type=1400 audit(1375759395.241:69): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=19445 comm="apparmor_parser"


    "Out of memory: Kill process 9321 (mysqld) score 107 or sacrifice child"
    貌似真的是因为内存不足? 必须升级内存?
    phuslu
        7
    phuslu  
       2013-08-06 14:36:34 +08:00
    Starry
        8
    Starry  
       2013-08-06 14:36:50 +08:00
    wodpress加个缓存插件!
    guoqiao
        9
    guoqiao  
    OP
       2013-08-06 14:38:43 +08:00
    @iZr 我是用了W3 Total Cache 这个插件, 不过缓存方式只有disk basic 和 disc enhenced可选,其它选项包括你说的memcached都是灰色禁用的. 这个是要付费还是要设置什么的?
    iZr
        10
    iZr  
       2013-08-06 14:39:30 +08:00   ❤️ 2
    @guoqiao 不需要付费.vps 安装memcached
    Mihuwa
        11
    Mihuwa  
       2013-08-06 14:40:12 +08:00
    @guoqiao memcached要自己在服务器上安装相应的服务。
    guoqiao
        12
    guoqiao  
    OP
       2013-08-06 14:41:24 +08:00
    @master 我现在用的W3 Total Cache, 跟你这个差别很大?
    guoqiao
        13
    guoqiao  
    OP
       2013-08-06 14:43:21 +08:00
    @iZr 不错,收了.
    cxh116
        14
    cxh116  
       2013-08-06 14:48:05 +08:00
    @guoqiao 参考这个,添加swap file,搞个1G

    https://wiki.archlinux.org/index.php/Swap
    skyworker
        15
    skyworker  
       2013-08-06 14:52:57 +08:00 via Android
    @iZr 迷茫了,七牛不是国内的cdn吗?
    skyworker
        16
    skyworker  
       2013-08-06 14:55:06 +08:00 via Android
    最简单的方案就是关闭mysql的innodb引擎,太费内存了,并且对wp这样的应用没什么实际帮助
    shiny
        17
    shiny  
       2013-08-06 14:57:45 +08:00
    wordpress 记得默认已经用 innodb 了吧…… 用监控宝监控内存波动,如果内存满了,swap也用了很多就必须加内存,要么用静态化插件。
    guoqiao
        18
    guoqiao  
    OP
       2013-08-06 15:00:41 +08:00
    @iZr 已安装并启用,多谢
    guoqiao
        19
    guoqiao  
    OP
       2013-08-06 15:22:52 +08:00
    @cxh116 多谢,加了个512M的swapfile.
    主机内存才512M, swapfile大于这个数貌似也意义不大吧?
    master
        20
    master  
       2013-08-07 02:32:52 +08:00
    @Mihuwa
    没用过 W3 Total Cache 呢,是说用 W3 Total Cache 插件的时候,客户还会因为数据库问题还是只能看到错误页而访问不了?

    看网站页面其实并不多,数据库里面的内容也不可能多的感觉,所以感觉数据库应该不会很占用资源
    而且展示性内容的网站用 MyISAM 也足矣,关掉InnoDB 用 MyISAM 也够了。
    我 512M 内存跑一千多篇日志的WP,还跑着Discuz 也都没发现说系统资源不够的问题,虽然磁盘I/O是对于数据库是有些堪忧。
    如果mysql没问题,但是系统资源不够用的话,是不是应该检查一下系统环境部署的问题,关注一下系统进程和内容使用情况吧,是不是装了很多没用的东西占用的资源,要是内存紧张还用memcache,我不知道是不是给内存资源火上浇油
    cst4you
        21
    cst4you  
       2013-08-07 08:29:50 +08:00 via Android
    我这边有之前1.3g内存的vps跑到百万pv的例子。
    主要还是根据我爱水煮鱼那个方法,用memcache做obj cache,用batcache插件缓存未游客访问的页面。
    晚上一般同时在线2500的时候负载不过2的。
    W3 total cache这个插件钩子太多了,用不好适得其反。
    clc3123
        22
    clc3123  
       2013-08-07 08:52:20 +08:00
    guoqiao
        23
    guoqiao  
    OP
       2013-08-07 10:42:43 +08:00
    @iZr 这个信息你是怎么看到的?
    iZr
        24
    iZr  
       2013-08-07 10:55:47 +08:00
    @guoqiao 源代码.
    xinghegu
        25
    xinghegu  
       2014-05-15 18:30:01 +08:00
    我的也是这样,楼主怎么解决的,帮我
    guoqiao
        26
    guoqiao  
    OP
       2014-05-20 19:13:17 +08:00
    @xinghegu 已经太久,不记得了.貌似是之前缓存插件设置不正确.
    leisudeng
        27
    leisudeng  
       2014-10-30 23:54:07 +08:00
    可以考虑用这个lowendscript的lnmp的一键包了,自用数台vps都装的它,运行稳定,内存占用相当低
    http://leisudeng.com/debian-tutorials/debian-tutorials-171-1.html
    leisudeng
        28
    leisudeng  
       2014-10-30 23:56:23 +08:00
    128m内存的OVZ vps运行wordpress都非常流畅
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2605 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 15:24 · PVG 23:24 · LAX 08:24 · JFK 11:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.