mysql运行报告_简单shell脚本监测mysql运行情况_MySQL

阿里云服务器上的mysql服务经常挂掉,每次需要自己去重启nginx,php,mysql服务器。其实只需要写一个简单的shell脚本监测mysql的运行进程,一旦这个进程消失就重启服务器。同时把脚本加入到系统服务中。为了不占用过多的资源,让脚本1分钟检查一次。

Monitor Shell #!/bin/bash#Supported by Letianwhile [ "1"="1" ]dostill_running=$(ps -ef |grep 'mysql' |grep -v 'grep')if [ "still_runnig" ];then:elseservice nginx restartservice php5-fpm restartservice mysql restartfisleep 60done

加入系统服务

还需要把脚本添加为系统服务,让脚本开机自启动。本方法采用适用于linux-ubuntu与Debian系统中的update-rc.d(创建/注册系统服务) 。 编写服务脚本放在/etc/init.d下。

在/etc/rc*.d中制作相关的link。K开头是kill, S开头是start, 数字顺序代表启动的顺序。可以采用update-rc.d 简化过程。

1405KD9501560-11157.jpg

这样建立了/etc/rc*.d中各种系统级别到脚本的软链接。然后执行命令

update-rc.d mysql-daemon start 90 1 2 3 4 5 . stop 52 0 6 .

start 90 1 2 3 4 5 . : 表示在1、2、3、4、5这五个运行级别中,按先后顺序,由小到大,第90个开始运行这个脚本。

stop 52 0 6 . :表示在0、6这两个运行级别中,按照先后顺序,由小到大,第52个停止这个脚本的运行。

关于update-rc.d update-rc.d updates the System V style init script links /etc/rcrunlevel.d/NNname whose target is the script /etc/init.d/name. These links are run by init when it changes runlevels; they are generally used to start and stop system services such as daemons. runlevel is one of the runlevels supported by init, namely, 0123456789S, and NN is the two-digit sequence number that determines where in the sequence init will run the scripts.

update-rc.d命令,用来自动升级System V类型初始化脚本。简单的讲就是,哪些东西是你想要系统在引导初始化的时候运行的,哪些是希望在关机或重启时停止的,可以用它来帮你设置。这些脚本的连接位于/etc/rc*.d/LnName,对应脚本位于/etc/init.d/Script-name。

ubuntu与Debian 的update-rc.d与RH的chkconfig工具相类似。然而chkconfig是一个二进制程序,而update-rc.d是一个Perl脚本。这些工具有不同的命令行选项,但是却执行类似的功能。[1]

设置完这些,用service –status-all命令可以查看mysql-daemon是否存在系统服务中。

1405KD9551560-2AP.jpg

Reference

[1].http://blog.csdn.net/aa2650/article/details/6304049

[2].http://manpages.ubuntu.com/manpages/hardy/man8/update-rc.d.8.html

[3].http://xiaoxia.org/2011/11/15/create-a-simple-linux-daemon/

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:php中文网

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值