合格linux運維人員必會的30道shell編程實踐題及講解-13

企業實踐題13:mysql

一、監控web服務是否正常,不低於3種監控策略。web

二、監控db服務是否正常,不低於3種監控策略。
要求間隔1分鐘,持續監控。sql

個人腳本1==============bash

#!/bin/bash
[ -f /etc/init.d/functions ] && . /ect/init.d/functions
if [ `netstat -nelp |grep -w 80|wc -l` -ne 0 ];then
    action "web service" /bin/true
else
    action "web service" /bin/false

if [ `netstat -nelp|grep -w 3306|wc -l` -ne 0 ];then
     action "db service" /bin/true
else
     action "db service" /bin/false

用定時任務crontab控制監控間隔時間
*/1 * * * * /bin/bash /scripts/listen_service.sh

個人腳本2===============curl

#!/bin/bash
[ -f /etc/init.d/functions ] && . /ect/init.d/functions
if [ `ps aux|grep -w http|wc -l` -ne 0 ];then
    action "web service" /bin/true
else
    action "web service" /bin/false

if [ `ps aux|grep -w http|wc -l` -ne 0 ];then
     action "db service" /bin/true
else
     action "db service" /bin/false

用定時任務crontab控制監控間隔時間
*/1 * * * * /bin/bash /scripts/listen_service.sh

個人腳本3================url

#!/bin/bash
[ -f /etc/init.d/functions ] && . /ect/init.d/functions
if [ "`curl -I http://127.0.0.1 2>/dev/null|head -1|egrep "200|302|301" -ne 0 ];then
    action "web service" /bin/true
else
    action "web service" /bin/false

if [ `mysql -uroot -p123456 -P 3306 -e "show databases;"|wc -l` -ne 0 ];then
     action "db service" /bin/true
else
     action "db service" /bin/false

用定時任務crontab控制監控間隔時間
*/1 * * * * /bin/bash /scripts/listen_service.sh
相關文章
相關標籤/搜索