In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how the VPS server in Linux automatically restarts the bash shell script based on system resources. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Here are two different operations:
1. Monitor the linux server load and memory usage, such as MySQl and php-fpm. When the load or memory footprint reaches the set value, restart the process automatically to avoid downtime: respond according to the remaining memory ratio
2. The VPS server automatically restarts according to CPU load and memory usage: reacts according to the actual amount of memory left.
First of all, let's talk about the files in the compressed package, which are auto_reboot.sh and check_reboot.sh, respectively, corresponding to the above two points. After downloading the compressed package, modify the parameters to match the configuration of your server. For more information, please see below.
1. Where auto_reboot.sh is set:
# set maximum memory footprint percentage
PID_MEM_MAX= "85"
# set maximum system load
SYS_LOAD_MAX= "3"
# set the name of the service to be monitored
NAME_LIST= "php-fpm mysql"
2. Where the check_reboot.sh is set:
# set the minimum remaining memory. Generally, at least 50 MB should be available (in megabytes)
FREE_MEM_MIN= "50"
# set maximum system load
SYS_LOAD_MAX= "3"
# set the minimum remaining memory for the restart service (in megabytes)
RESTART_FREE_MEM_MIN= "500s"
# set the name of the service to be monitored
NAME_LIST= "httpd mysqld"
The red part needs to be modified according to your server hardware configuration. After the modification, upload the two * .sh files to the server under the path that Root can access, add scheduled tasks, and set them to check every minute.
Crontab-e
* / bin/bash/root/auto_reboot.sh
The above code notes that each * sign is divided by the Tab key, and the path behind is the path of the file you just uploaded. Make sure that root can access the path, and pay attention to the correct location of the file.
Make sure that bc is installed on your Linux system, otherwise an error will occur.
To see if bc is installed, you can use the command:
Bc-v
If not, centos can install it with yum-y install bc
You can use the following command to test whether the script is running properly (if so, nothing should be returned)
Sh/ bin/bash/root/auto_reboot.sh
If there is an error like syntax error near unexpected token `do, please do it yourself, Baidu or Google.
Thank you for reading! On the "Linux VPS server how to automatically restart the bash shell script according to system resources" this article shares here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.