簡單的服務連接埠檢測及警示

來源:互聯網
上載者:User

一、設定管理員的smtp資訊

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

二、service_check.sh檢測指令碼內容

#!/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

警示機制說明:如果檢測到連接埠不存在時會發資訊,在連接埠恢複正常後會發送recovery資訊確認


三、加入定時任務

*/5 * * * *  sh /root/lee/service_check.sh

四、測試

手動關閉mysqld服務

650) this.width=650;" src="http://www.bkjia.com/uploads/allimg/131227/23460433K-0.png" title="映像 001.png" alt="152038598.png" />

過段時間會收到簡訊,簡訊

650) this.width=650;" src="http://www.bkjia.com/uploads/allimg/131227/234604O20-1.png" title="IMG_0756.PNG" alt="152114954.png" />

手動開啟mysqld服務

650) this.width=650;" src="http://www.bkjia.com/uploads/allimg/131227/234604L25-2.png" title="映像 002.png" alt="152144989.png" />

過5分鐘會有個恢複的回執

650) this.width=650;" src="http://www.bkjia.com/uploads/allimg/131227/23460423a-3.png" title="IMG_0757.PNG" alt="152229295.png" />


五、指令碼內容已經在附件中,可以自行測試




本文出自 “明日香” 部落格,請務必保留此出處http://leezqang.blog.51cto.com/1525874/1301577

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.