Script for automatically monitoring VPS load and restarting Web services

Source: Internet
Author: User
In fact, VPS is basically the same as an ordinary independent Linux server in terms of use, because the current virtualization technology and very mature, but there is a big difference between VPS and single server, that is, system resources and performance. Generally, a VPS is composed

In fact, VPS is basically the same as an ordinary independent Linux server in terms of use, because the current virtualization technology and very mature, but there is a big difference between VPS and single server, that is, system resources and performance. Generally, VPS is divided by an independent server, so the advantages of resources and performance are far inferior to those of independent servers.

Taking the DDOS attacks against VPS some time ago as a matter of fact, DDOS is also using a large number of initiated requests, resulting in VPS (or server) memory resources being attacked to be exhausted, and the system load is too high, as a result, the Http service on port 80 does not respond, thus achieving the ultimate attack goal. Although DDOS is hard to prevent, there are still some ways to reduce the impact of DDOS. For example, you can regularly monitor the system status and then automatically restart the Web service. this is also a method described in this article.

When VPS is attacked, some system indicators can reflect whether the system is under attack. one is to check the remaining memory. of course, this is not the most accurate method, in addition, you can view the average load of the Linux system.

Introduction to Linux system load

The average system load is defined as the average process tree in the running queue within a specific time interval. If a process meets the following conditions, it will be in the running queue:

-It has no results waiting for I/O operations.

-It does not take the initiative to enter the waiting state (that is, it does not call 'wait ')

-Not stopped (for example, waiting for termination)

In Linux, you can view the average load of the current system through many commands, such as the w, top, or uptime command.

The command output indicates the average number of processes in the running queue in the past 1, 5, and 15 minutes.

Generally, these values are different based on the number of CPUs in the system. for single-core CPUs, if the load value reaches 1, the system load has reached 100%, however, for a dual-core system, 1 indicates that the system load is only about 50%.

In a multi-processor system, the average load is determined by the number of kernels. In 100% load computing, 1.00 represents a single processor, while 2.00 represents two dual processors, so 4.00 indicates that the host has four processors.

Automatically restart the Web service based on the system load value

The following script takes the VPS with the Apache server as an example to regularly determine the system load value. when the value reaches 5, the system is deemed to be overloaded. at this time, the script automatically restarts the Apache service, release system resources to ensure the smooth operation of VPS servers.

* Note: The script is from the network. it is not original and the source is unknown. I have made some changes.

#! /Bin/sh
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.