Home > OS >  The Web server monitoring and email reminder
The Web server monitoring and email reminder

Time:10-07

Linux training recently has made the Web server to monitor the subject, the Internet to find a tutorial, a combination of some people post and own experience for everyone to send a relatively complete tutorial,

A: mailx installation, configuration sendmailx,

Yum install - y mailx

Modify/etc/mail. Add the following rc configuration, input vim/etc/mail. Rc

The set [email protected]
The set smtp=smtp.163.com
The set SMTP auth - user=# XXX netease mail name
The set SMTP auth - password=# XXX here to write SMTP authorization code, need to mail Settings
The set SMTP - auth=login

, of course, here you can also use other E-mail, such as qq mailbox, need to change the above code is

Using mail order email:
Echo "email" | title title [email protected] mail - s - s [email protected] & lt; The file

Open SMTP authorization code: 163
1, after entering email home page, click Settings
2, select POP3/SMTP, IMAP
3, in the pop-up page check the POP3/SMTP service
4, pop-up set authorization code reminder, click ok
5, check the set authorization code position behind the beginning of the
6, pop-up authentication information, through the mobile phone number verification code, if there is no binding mobile phone number to bind again after the operation,
7, enter the authentication code, only three times a day, don't waste your best,
8, set up the authorization code, need to enter it twice, remember,
9, pop up a small window, click ok,
10, can see set the authorization code has been open, open, after the success of the open, mobile phone will receive a text message, among them the authorization code information,
11, SMTP/POP3 service to success at the same time,

2: write to monitor file url,

Under the root directory:
Vim url
Input to monitor website, for example, I want to monitor is a domain name, so that the contents of the file is:
www.xxx.com

3: write the monitoring script monitor. Sh,

Under the root directory:
Vim monitor. Sh

Write a script:
#!/bin/bash
# monitoring web service and email to
While true
Do
Remember to turn the Mail="[email protected]" # mailbox modified into your
FailCount=0
Retval=0
GetUrlStatus () {
For ((I=1; i<=3; I++)) # use i++ visits, if wget twice timeout anomaly judgment site
Do
Wget -t 3 - tries=1 - spiders ${1} & gt;/dev/null 2 & gt; & 1 # T timeout, - tries to try once, spiders spider
[0] $? - can be & amp; & Let FailCount +=1; # when accessing a timeout, $? Is not equal to zero, then the FailCount plus 1
The done
The Date=` Date + % F "" % H: % M `
If [1] $FailCount - gt; Then
Retval=1
Echo "check the fail!!!!!! , sendmail... "
# # use mutt
# echo - e "Date: $Date \ nProblem: $url is not running." | "web server Monitor" mutt - s $Mail
Echo "Date: $Date \ n Problem: $url service hanged" | mailx - v - "service monitoring remind" s $Mail
The else
Retval=0
Echo "Date: $Date $url is running."
Fi
Return the $Retval
# if the return value is zero, then the normal exit the loop and no 0, continue to cycle
}
For the url in ` cat url | sed '/^ #/d `
Do
# GetUrlStatus $url & amp; & Echo yes | | echo no GetUrlStatus $url
The done
Sleep 600 # infinite loop, set once every 600 s
The done

The code above is moved to the Internet, the measured with,

Four: the startup script, will monitor echo output to the specified file. The log,
Bash monitor. Sh
Nohup sh monitor. Sh & gt;> The monitor. The log & amp;

Five: exit the system login again after check script running state,
Ps - ef | grep monitor

Six: look at the monitor, log and email verification,

In this step, we put our website to shut down here I use more direct way, first close the HTTPD process directly,

Systemctl stop HTTPD

After shut down web site can view the monitor scripts and observe whether to have the correct mailbox mail sent,

The cat monitor. The log


  • Related