VPS侦探论坛

 找回密码
 注册
查看: 3972|回复: 8

每天凌晨mysql会挂掉,错误日志里没有记录,请问有没有mysql挂掉自动重启的脚本,谢谢

[复制链接]
发表于 2016-9-24 22:35:06 | 显示全部楼层 |阅读模式

刚刚装好lnmpa1.3环境几天,数据恢复以后,每天凌晨mysql会挂掉,错误日志里没有记录到错误信息,
请问有没有检测到mysql挂掉自动重启的脚本,类似502错误自动重启的脚本,,谢谢

配置 阿里云 1核2G
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2016-9-25 11:49:25 | 显示全部楼层


  1. #!/bin/bash
  2. # author: licess
  3. # website: https://lnmp.org

  4. Check=`ps -ef|grep mysqld|grep -v grep|wc -l`

  5. if [ $Check -eq 0 ]; then
  6.     /etc/init.d/mysql restart
  7. fi
复制代码
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2016-9-25 14:38:50 | 显示全部楼层

谢谢军哥
我是不是要 使用crontab 执行定时任务 来配合这个脚本使用?我现在是 通过crontab每分钟执行一次你写的脚本,
测试了一下,可以自己检测到mysql停止并自己启动了,

因为crontab最少只能是一分钟,是不是还有什么方式,可以做到实时检测并启动的?

[ 本帖最后由 Jouleken 于 2016-9-25 14:52 编辑 ]
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2016-9-25 20:51:12 | 显示全部楼层



定时任务都是配合crontab的

把if语句改成while,放在screen 中运行
  1. #!/bin/bash
  2. # author: licess
  3. # website: https://lnmp.org

  4. while true;do
  5. Check=`ps -ef|grep mysqld|grep -v grep|wc -l`

  6. if [ $Check -eq 0 ]; then
  7.     /etc/init.d/mysql restart
  8.         sleep 5
  9. fi
  10. done
复制代码
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2016-9-27 16:10:12 | 显示全部楼层

我的也是这样 进程每天不定时被kill,是不是内存溢出?

军哥运维代购:http://shop63846532.taobao.com/

发表于 2016-9-27 16:11:41 | 显示全部楼层

Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 1576]     0  1576    19970      908   0       0             0 AliHids
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 1605]   501  1605    89934    18741   0       0             0 php-fpm
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 1629]     0  1629     7905        1   0       0             0 gshelld
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 1645]   501  1645    89848    16212   0       0             0 php-fpm
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 1678]     0  1678   406250     2611   0       0             0 yunsuo_agent_se
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 1697]     0  1697     4096       31   0       0             0 yunsuo_agent_gu
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 1770]     0  1770     1016        2   0       0             0 mingetty
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 1772]     0  1772     1016        2   0       0             0 mingetty
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 1774]     0  1774     1016        2   0       0             0 mingetty
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 1776]     0  1776     1016        2   0       0             0 mingetty
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 1778]     0  1778     1016        2   0       0             0 mingetty
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 1780]     0  1780     1016        2   0       0             0 mingetty
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 1824]   501  1824    89932    20747   0       0             0 php-fpm
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 1828]   501  1828    91744    17370   0       0             0 php-fpm
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 3729]   501  3729    89808    20474   0       0             0 php-fpm
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 3730]   501  3730    89688    18032   0       0             0 php-fpm
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 3732]   501  3732    88855    19515   0       0             0 php-fpm
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 3733]   501  3733    89539    20052   0       0             0 php-fpm
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 3734]   501  3734    89520    19250   0       0             0 php-fpm
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 6440]     0  6440    26549       76   0       0             0 mysqld_safe
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 7097]   501  7097    81361    12019   0       0             0 php-fpm
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 7175]   500  7159   427568    51444   0       0             0 mysqld
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: [ 7176]     0  7176    26518      287   0       0             0 sh
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: Out of memory: Kill process 7175 (mysqld) score 34 or sacrifice child
Sep 27 14:39:01 iZ28jcqqr7lZ kernel: Killed process 7175, UID 500, (mysqld) total-vm:1710272kB, anon-rss:204760kB, file-rss:1016kB


哪位帮我看下啊
发表于 2016-9-27 19:12:29 | 显示全部楼层

回复 6# 的帖子


内存不够用被系统kill掉了
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2016-9-27 20:19:47 | 显示全部楼层

以前1.2版本的时候从来没这问题,除了改装1.2还有什么办法么?
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2016-9-28 09:01:30 | 显示全部楼层

回复 8# 的帖子


要先确定好原因才能有具体解决方法

军哥运维代购:http://shop63846532.taobao.com/

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-4-27 13:15 , Processed in 0.029248 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表