Linux system resource load is too high and Apache shell script is automatically restarted

Source: Internet
Author: User
Tags pkill
Linux system resource load is too high and Apache shell script is automatically restarted

 

When we routinely maintain Apache Web servers in Linux, the endless loop caused by crawler crawling cannot jump out, or the collection of data from peers brings huge additional overhead to the server load, seriously, Apache will be shut down over load 2, leading to the failure of the website to provide external services, resulting in irreparable losses to enterprises. Find the relevant shell script for the warning mechanism for automatically restarting Apache on the Internet, and share it with more administrators. Make changes based on your actual situation. It is applicable to all web services that can be installed through service httpd START | stop or source code to restart Apache VPs or servers. Finally, execute the command every several minutes in the crontab settings.

[Root @ club root] # Cat/admin_tools/loadavg_restart_apache.sh
#! /Bin/sh

# Crontab usage: */3 *****/admin_tools/loadavg_restart_apache.sh>/admin_tools/restart_apache.log

Top_sys_load_num = 3
Sys_load_num = 'uptime | awk' {print $ (NF-2)} '| SED's /,//''
 
Echo $ (date + "% Y-% m-% d") 'uptime'
If ['echo "$ top_sys_load_num <$ sys_load_num" | BC '-EQ 1]
Then
   Echo "#0 #" $ (date + "% Y-% m-% d % H: % m: % s ") "pkill httpd" 'ps-Ef | grep httpd | WC-l'
   /Home/Server/Apache/bin/apachectl stop
   Sleep 8
   Pkill httpd
   Sleep 8
   For I in 1 2 3
   Do
       If ['pgrep httpd | WC-l'-Le 0]
       Then
           /Home/Server/Apache/bin/apachectl start
           Sleep 30
           Echo "#1 #" $ (date + "% Y-% m-% d % H: % m: % s ") "Start httpd" 'ps-Ef | grep httpd | WC-l'
       Fi
   Done
Else
   If ['pgrep httpd | WC-l'-Le 0]
   Then
       /Home/Server/Apache/bin/apachectl start
       Sleep 30
       Echo "#2 #" $ (date + "% Y-% m-% d % H: % m: % s ") "Start httpd" 'ps-Ef | grep httpd | WC-l'
   Fi
Fi

Related Article

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.