WEB站伺服器監控郵件報警配置
由于部分WEB站舊伺服器仍舊使用2003系統,經常出現伺服器内分頁大滿,伺服器記憶體溢出等情況,導緻整台伺服器WEB站無法打開的情況,伺服器太多尋查難度較大,有時難以及時發現處理,影響客戶體驗度。于是個人寫了一個郵件報警SHELL,當伺服器整體無法打開時,及時郵件報警通知。
首先還是要安裝一台LINUX,其次安裝上MAILX郵件系統。
可以使用:Yum install mailx –y 安裝,這裡已經安裝通過檢視。

配置郵件系統收發設定:這裡使用163郵件,感覺比較友善。
Vim /etc/mail.rc
加入下列設定項:
寫一個SHELL腳本:monitor.sh
#!/bin/bash
author by jerry(2011-2019)
rm -rf /server/script/log.txt
for line in
cat -A /server/script/ip.txt
do
domains=
echo $line |cut -d"^" -f1|awk -F"/" '{print $1}'
hostip=
echo $line |cut -d"^" -f1|awk -F"/" '{print $2}'
status=
curl -sI $domains |grep "200 OK" |awk '{print $2}'
if [ "$status" != "200" ]
then
curl -sI $domains |grep "200 OK" |awk '{print $2}'
[ "$status" != "200" ] && status=
curl -o /dev/null -s -w %{http_code} $domains
fi
echo "$hostip --- $status" >>/server/script/log.txt
localtime=
date +%Y-%m-%d" "%H:%M:%S
[ "$status" != "200" ] && echo "Message Server $hostip Report Error,Pls Check It $status" |mail -s "$hostip warnning $localtime" [email protected]
done
另一種方式腳本寫法(推薦使用更高效):
cat -A /server/script/ip.txt
domain=
echo $line |cut -d"/" -f1
echo $line |cut -d"/" -f2|awk -F"$" '{print $1}'
wget --spider -nv $domain -o /server/script/cache
cat /server/script/cache|awk '{print $5}'
ipcount=
awk '{print $3}' /server/script/log.txt |grep 200|wc -l
date +%Y-%m-%d" "%H:%M:%S
[ $ipcount != 34 ] && cat /server/script/log.txt |grep -Ev 200 |mail -s "Message Server warnning $localtime" [email protected]