The Linux VPS server automatically restarts the bash shell script based on system resources.

  

There are two different operations described here: 1. Monitor the Linux server load and memory usage, such as MySQl, php-fpm, when the load or memory usage reaches the set value. , will automatically restart the process to avoid downtime: according to the proportion of remaining memory response 2, VPS server automatically restart according to CPU load and memory usage: according to the remaining actual memory number to talk about the file inside the compressed package, respectively, auto_reboot.sh And check_reboot.sh, corresponding to the above 1, 2 and 2 points. After downloading the compressed package, first modify the parameters inside to match the configuration of your own server. For details, see the following settings: auto_reboot.sh: # Set the maximum memory usage percentage PID_MEM_MAX=”85″ # Set the maximum system load SYS_LOAD_MAX= ”3″ # Set the service name to be monitored NAME_LIST=”php-fpm mysql”

2. The place where check_reboot.sh is set: # Set the minimum remaining memory, generally at least 50M is available (unit megabytes) FREE_MEM_MIN=”50″ # Set the maximum system load SYS_LOAD_MAX=”3″ # Set the minimum remaining memory of the restart service (in megabytes) RESTART_FREE_MEM_MIN=”500″ # Set the service name to be monitored NAME_LIST=”httpd mysqld” The red place needs to be modified according to the configuration of the server hardware. After the modification, upload the two *.sh files to the path that Root can access on the server, add the scheduled task, and set the check every minute. crontab -e * * * * * /bin/bash/root/auto_reboot.sh Note the code above Each * is followed by the Tab key. The trailing path is the path of the file you just uploaded. Be sure to access the path that root can access. Note that the location of the file should be correct. Make sure that bc is already 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 installed, centos can install it with yum -y install bc

You can use the following command to test whether the script works normally (if it is normal, it should not return) Anything) sh /bin/bash/root/auto_reboot.sh If you get a syntax error near unexpected token `do, please do Baidu or Google. good luck.

Copyright © Windows knowledge All Rights Reserved