Monitor the running status of system services mysqld and httpd
Environment requirements:
Shell. sh is used to monitor the running status of the system service mysqld every five minutes,
If the mysqld process has been stopped, append the log information in the/var/log/messages file, including the stop time, and restart the mysqld service;
Otherwise, no operation is performed:
As follows:
650) this. width = 650; "title =" image001.png "src =" http://www.bkjia.com/uploads/allimg/131227/1K033G56-0.png "/>
The content is as follows:
#! /Bin/bash
Pgrep-x mysqld &>/dev/null
If [$? -Ne 0]
Then
Echo "At time: 'date': MySQL server is down.">/var/log/messages
Servicemysqld start
Else
Echo "MySQL server is running ."
Fi
Add the corresponding permissions and execute the script to verify the effect:
650) this. width = 650; "title =" image003.png "src =" http://www.bkjia.com/uploads/allimg/131227/1K0334N3-1.png "/>
Set the corresponding scheduled task
Environment requirements:
Write a script to monitor the running status of the system service httpd. The requirements are as follows:
When the service status is abnormal, log information is recorded in the "/var/log/htmon. log" file.
Automatically restarts an abnormal httpd service. If the httpd service fails to be restarted, restart the server host.
Combined with crond scheduled tasks, the monitoring task is executed every 15 minutes from Monday to Friday.
1. Create the script htmon. sh in the/opt directory. The script content is as follows:
As follows:
650) this. width = 650; "title =" image005.png "src =" http://www.bkjia.com/uploads/allimg/131227/1K0332O2-2.png "/>
The content is as follows:
#! /Bin/bash
/Sbin/service httpd status &>/dev/null
If [$? -Ne 0]
Then
Echo "httpd is down. at time: 'date'">/var/log/httpshell. log
/Sbin/service httpd restart
/Sbin/service httpd status &>/dev/null
If [$? -Ne 0]
Then
/Sbin/chkconfig -- level 2345 httpd on
/Sbin/shutdown-r now
Fi
Fi
2. Create a crontab to schedule a task,
*/15 */root/httpshell. sh
650) this. width = 650; "title =" image007.png "src =" http://www.bkjia.com/uploads/allimg/131227/1K0333T9-3.png "/>
3. Execute the script and verify the effect:
650) this. width = 650; "title =" image009.png "src =" http://www.bkjia.com/uploads/allimg/131227/1K033M46-4.png "/>
[Root @ shell ~] # Chmod + x httpshell. sh
[Root @ shell ~] #./Httpshell. sh
[Root @ shell ~] # Tail-5/var/log/httpshell. log
This article from the "heard" blog, please be sure to keep this source http://wenzhongxiang.blog.51cto.com/6370734/1229558