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

Supervisor 监控 Mysql 无法自动启动~~

  •  
  •   GreenJoson · 2015-02-01 01:58:41 +08:00 · 8170 次点击
    这是一个创建于 3377 天前的主题,其中的信息可能已经有所发展或是发生改变。

    VPS经常因为Mysql,apahce 2G内存满而导致Mysql经常挂~~
    经常出现Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)这个问题 ~~

    每次都需要手动service mysql restart 重启。。但问题隔两天三后又出现……甚是烦人~

    装了Supervisor 监控,手动Kill all mysql 可以自动启动进程 ,但当上面的问题出现后,确无法自动启动?这么坑爹的问题,折腾了我好久好久~~~

    mysql 错误日志~~
    150201 1:37:09 InnoDB: The InnoDB memory heap is disabled
    150201 1:37:09 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    150201 1:37:09 InnoDB: Compressed tables use zlib 1.2.7
    150201 1:37:09 InnoDB: Using Linux native AIO
    150201 1:37:09 InnoDB: Initializing buffer pool, size = 512.0M
    150201 1:37:09 InnoDB: Completed initialization of buffer pool
    150201 1:37:09 InnoDB: highest supported file format is Barracuda.
    150201 1:37:09 InnoDB: Waiting for the background threads to start
    150201 1:37:10 InnoDB: 5.5.41 started; log sequence number 1672214
    150201 1:37:10 [ERROR] /usr/sbin/mysqld: unknown variable 'defaults-file=/etc/mysql/my.cnf'
    150201 1:37:10 [ERROR] Aborting

    150201 1:37:10 InnoDB: Starting shutdown...
    150201 1:37:11 InnoDB: Shutdown completed; log sequence number 1672214
    150201 1:37:11 [Note] /usr/sbin/mysqld: Shutdown complete

    Supervisor 输出定向日志:
    150127 18:48:02 InnoDB: The InnoDB memory heap is disabled
    150127 18:48:02 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    150127 18:48:02 InnoDB: Compressed tables use zlib 1.2.7
    150127 18:48:02 InnoDB: Using Linux native AIO
    150127 18:48:02 InnoDB: Initializing buffer pool, size = 512.0M
    150127 18:48:02 InnoDB: Completed initialization of buffer pool
    InnoDB: Unable to lock ./ibdata1, error: 11
    InnoDB: Check that you do not already have another mysqld process
    InnoDB: using the same InnoDB data or log files.
    150127 18:48:02 InnoDB: Retrying to lock the first data file
    InnoDB: Unable to lock ./ibdata1, error: 11
    InnoDB: Check that you do not already have another mysqld process
    InnoDB: using the same InnoDB data or log files.
    InnoDB: Unable to lock ./ibdata1, error: 11
    InnoDB: Check that you do not already have another mysqld process
    InnoDB: using the same InnoDB data or log files.
    InnoDB: Unable to lock ./ibdata1, error: 11
    InnoDB: Check that you do not already have another mysqld process
    InnoDB: using the same InnoDB data or log files.
    InnoDB: Unable to lock ./ibdata1, error: 11
    InnoDB: Check that you do not already have another mysqld process
    InnoDB: using the same InnoDB data or log files.
    InnoDB: Unable to lock ./ibdata1, error: 11
    InnoDB: Check that you do not already have another mysqld process
    InnoDB: using the same InnoDB data or log files.
    InnoDB: Unable to lock ./ibdata1, error: 11
    InnoDB: Check that you do not already have another mysqld process
    InnoDB: using the same InnoDB data or log files.
    InnoDB: Unable to lock ./ibdata1, error: 11
    InnoDB: Check that you do not already have another mysqld process
    InnoDB: using the same InnoDB data or log files.
    InnoDB: Unable to lock ./ibdata1, error: 11

    都是这个信息。。足足有80多万条这个信息。。想死的心都有了~~~
    supervisord.conf 配置信息这样写的~~
    [program:mysqld]
    ;/bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/var --pid-file=/usr/local/mysql/var/dedi-us1.agenciawebsul.com.br.pid
    command=/usr/sbin/mysqld /var/run/mysqld/mysqld.pid /var/run/mysqld/mysqld.sock --defaults-file=/etc/mysql/my.cnf --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306 2>&1 > /dev/null &
    user=mysql
    priority=1
    numprocs=1
    startsecs=10
    startretries=20
    autostart=true
    autorestart=true
    redirect_stderr=false
    stdout_logfile=/var/log/supervisor/run.log
    stderr_logfile=/var/log/supervisor/error.log

    请高手,帮忙解决。。不剩感激~~~

    16 条回复    2015-02-02 13:07:37 +08:00
    seki
        1
    seki  
       2015-02-01 06:11:24 +08:00   ❤️ 1
    msg7086
        2
    msg7086  
       2015-02-01 07:33:42 +08:00 via iPhone
    建议你考虑一下少用一些内存,而不是杀数据库玩。
    bigzhu
        3
    bigzhu  
       2015-02-01 08:22:33 +08:00 via Android
    这是在用错误的方式解决问题
    首先,不要再用 Supervisor 了,让这么个影响性能的东西自以为是的自动重启你的进程真的妥当么。进程监控用 http://highwe. net 能够知晓存活状态就可以了。

    其次,找到真正进程消失的原因,内存不够用,至少你可以用增加swap的方式临时解决下。还是得找找耗费那么多内存的原因,解决之…
    Livid
        4
    Livid  
    MOD
       2015-02-01 08:34:22 +08:00
    buffer pool 的尺寸减小一点,apache 的 process 数量也减少一些。
    msg7086
        5
    msg7086  
       2015-02-01 08:40:10 +08:00 via iPhone
    重启的话systemd自己就可以做到了。但是就像上面说的,你这么玩,总有一天数据库会崩溃,自食其果
    2owe
        6
    2owe  
       2015-02-01 09:23:12 +08:00
    写 crontab 脚本或者 supervisior 用的 daemon 脚本,每次检查进程情况、内存占用,顺便重启。

    当然如上面 V 友们所说,优化其他程序内存占用(apache、mysql)可能都是必要的。

    能在当前花点时间解决的问题,不建议盲目加机器配置。
    lincanbin
        7
    lincanbin  
       2015-02-01 10:27:21 +08:00 via Android
    估计是apache挤占掉了MySQL,建议检查一下,在安装了WordPress的vps中非常常见。
    然后我建议写个定时脚本,每隔1分钟检查mysqld还活着没,死了就restart。
    humiaozuzu
        8
    humiaozuzu  
       2015-02-01 10:34:11 +08:00
    Supervisor 不是用来跑 Mysql 这类服务的进程的。。。换 monit 都行
    GreenJoson
        9
    GreenJoson  
    OP
       2015-02-01 22:25:38 +08:00
    @seki 这个我看过了。。但是我百度,google过很多。。写的配置项都跟我一样~~~

    我这个也是一个朋友帮我整的~~
    GreenJoson
        10
    GreenJoson  
    OP
       2015-02-01 22:28:53 +08:00
    @bigzhu 这么一说,我得把supervisor 卸载了~~
    其实我swap已经加了2G多了~~
    因为这个是CMS。用的是TP框架2.1的版本,也不是我自己写的~~但是同样用这个CMS的人,都没有我这种情况。我一直查mysql error.log ,但折腾了这么久,依然还是没有找到真正被爆掉的原因~
    GreenJoson
        11
    GreenJoson  
    OP
       2015-02-01 22:30:11 +08:00
    @Livid buffer pool 我之前是128的时候,也挂,我才调到512M~~~apache process 没调过~~

    我用的是vestacp 主机面板带环境~~
    GreenJoson
        12
    GreenJoson  
    OP
       2015-02-01 22:38:19 +08:00
    @lincanbin 。。。。我对Linux 不在行,不会写crontab 脚本~~不过你说的情况,apache 如果被CC的话,就有可以挤掉。或者apache占用过大,就会挤掉mysql,这个可能性也很大~~唉,就不知道怎么下手。~
    GreenJoson
        13
    GreenJoson  
    OP
       2015-02-01 22:40:40 +08:00
    @msg7086 杀数据库玩~??我不是杀着玩,我是说手动Kill有效,但是mysql自动挂掉,就无法重新启动~~
    GreenJoson
        14
    GreenJoson  
    OP
       2015-02-01 22:40:54 +08:00
    一会功夫,,又挂了。。实在找不出原因~~
    msg7086
        15
    msg7086  
       2015-02-02 02:33:38 +08:00   ❤️ 1
    @GreenJoson 你在小内存上跑apache,连接数一大马上跪内存,然后oom_killer就开始随便杀数据库玩了。如果你只是跑php的话,nginx+php-fpm内存占用要小得多,节约点的话1G内存都够跑,自然也不用担心数据库被杀掉的情况了。
    GreenJoson
        16
    GreenJoson  
    OP
       2015-02-02 13:07:37 +08:00
    @msg7086 我卸载了~Supervisor ,开了Nginx caching,再看看会不会好点~~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1044 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:41 · PVG 07:41 · LAX 16:41 · JFK 19:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.