1. Configure smtp information for the server
vim /etc/mail.rcset from=XXX@XXX.com smtp=smtp.xxx.com smtp-auth-user=XXX@XXX.com smtp-auth-password=xxxxx smtp-auth=login
Ii. service_check.sh check script content
#!/bin/bashfor port in 80 3306 10050 10022; doif `netstat -tnlp |grep $port &> /dev/null` ; then if `tail -4 /root/lee/service_status.log |grep "$port failed" &> /dev/null` ;thenecho "`date +%F-%H:%M:%S` [`hostname`] `/sbin/ifconfig eth0 |grep "inet addr" |awk '{split($2,a,":"); print a[2]}'` [$port recovery]"> /root/lee/mail_content.txtmail -s "$port recovery" XXXXXXXXXX@139.com < /root/lee/mail_content.txt fiecho "`date +%F-%H:%M:%S` $port no problem" >> /root/lee/service_status.logelseecho "`date +%F-%H:%M:%S` $port failed................" >> /root/lee/service_status.logecho "`date +%F-%H:%M:%S` [`hostname`] `/sbin/ifconfig eth0 |grep "inet addr" |awk '{split($2,a,":"); print a[2]}'` [$port down]"> /root/lee/mail_content.txtmail -s "$port failed" XXXXXXXXXXXX@139.com < /root/lee/mail_content.txtfidone
Alarm Mechanism Description: If the port does not exist, a message is sent. After the port returns to normal, a recovery message is sent for confirmation.
3. Add scheduled tasks
*/5 * * * * sh /root/lee/service_check.sh
Iv. Test
Manually disable the mysqld service
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131227/23460433K-0.png "title =" image 001.png" alt = "152020.8.png"/>
You will receive a text message or text message later.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131227/234604O20-1.png "title =" IMG_0756.PNG "alt =" 152114954.png"/>
Manually enable the mysqld service
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131227/234604L25-2.png "title =" image 002.png" alt = "152144989.png"/>
There will be a recovery receipt in 5 minutes
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131227/23460423a-3.png "title =" IMG_0757.PNG "alt =" 152229295.png"/>
5. The script content is already included in the attachment. You can test it by yourself.
This article from the "Sun Xiang" blog, please be sure to keep this source http://leezqang.blog.51cto.com/1525874/1301577