Monitor the running status of system services mysqld and httpd

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.