liunx服务器监控脚本(监控nginx,php-fpm,mysql)

服务器状态监控脚本
本文介绍了一个用于监控服务器上PHP-FPM、Nginx及MySQL服务运行状态的Bash脚本。当检测到这些服务未运行时,脚本将通过执行特定命令启动相应服务,并通过调用phpalarm.php发送警告。
#!/bin/bash
ip=$(ifconfig eth0 | awk -F'addr:|Bcast' '/Bcast/{print $2}')
num=`ps aux | grep php-fpm | grep -v grep | wc -l`
if [ $num -eq 0 ];then
        php alarm.php  "php-fpm is not running on $ip"
        /etc/init.d/php-fpm start
fi

num=`ps aux | grep nginx | grep -v grep | wc -l`
if [ $num -eq 0 ];then
        php alarm.php  "nginx is not running on $ip"
        /etc/init.d/nginx start
fi

cmd=`/usr/local/mysql/bin/mysqladmin -h127.0.0.1 -uroot -proot ping`
echo "$cmd" | grep -q "alive"
if [ $? -ne 0 ];then
        php alarm.php  "mysql is not running on $ip"
        /etc/init.d/mysql start
fi

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值