服务器监控:
Shell调用钉钉机器人实现网站服务巡检脚本_钉钉自动检测网站-CSDN博客
Curl-all: 定时轮询各网站,访问正常不:
#!/bin/bash
#主机信息
name=`hostname`
date=`date '+%Y-%m-%d-%H:%M:%S'`
# 定义服务字典
declare -A dic
dic=(
[https://baidu.com]="baidu"
[https://www.baidu.com]="baidu2"
)
#自定义接入钉钉函数
function SendMessageToDingding(){
#钉钉机器人接口地址
url="https://oapi.dingtalk.com/robot/send?access_token=s13e94d23e032ffde10586dd37eb92b5a91b0170f0c2dd4bdb2a4e5955eb01"
#推送到钉钉
curl -XPOST -s -L $url -H "Content-Type:application/json" -H "charset:utf-8" -d "
{
\"msgtype\": \"text\",
\"text\": {
\"content\": \"监控主机名wpwoo:$1\n主机IP: $2\n 异常服务:$3\n 巡检时间:$4\"
},
'at': {
'isAtAll': true
}
}"
}
# 服务检查
for i in ${!dic[*]}
do
k=`curl -I -s ${i} | grep 'HTTP/1.1'| awk '{print $2}'`
if [[ ${k} -ne 200 ]];then
SendMessageToDingding ${k} ${dic[${i}]} ${i} $date
fi
done
运维自动化:
宝塔自动检测状态,并重启PHP、redis、MySQL、Nginx服务 – 田小檬博客
Nginx监控,
异常后自动重启脚本
#!/bin/bash
# Linux监控Nginx服务,关闭就自动重启
nginx_procnum=`ps -ef|grep "nginx"|grep -v grep|wc -l`
if [ $nginx_procnum -eq 0 ]
then
echo $(date) "Success,Nginx重启成功!" >> /var/log/nginxmonitor.log
/etc/init.d/nginx start
else
sleep 5
echo "Nginx正常运行中..."
fi
MySQL监控:
#!/bin/bash
# Linux监控MySQL服务,关闭就自动重启
pgrep -x mysqld &> /dev/null
if [ $? -ne 0 ];then
bash /www/server/panel/script/rememory.sh
/etc/init.d/mysqld start
echo "监控到MySQL已停止,已执行重启计划,时间: `date "+%Y-%m-%d %H:%M:%S"` " >> /www/mysql_jiankong.log
Fi
redis监控:
#!/bin/bash
# Linux监控redis服务,关闭就自动重启
pgrep -x redis &> /dev/null
if [ $? -ne 0 ];then
/etc/init.d/redis start
Fi
PHP监控:
#!/bin/bash
# Linux监控PHP服务,关闭就自动重启
pgrep -x php-fpm &> /dev/null
if [ $? -ne 0 ];then
/etc/init.d/php-fpm-74 restart
echo "监控到php74已停止,已执行重启计划,时间: `date "+%Y-%m-%d %H:%M:%S"` " >> /www/php_jiankong.log
Fi