Last update at :2024-06-17,Edit by888u
When some of us operate projects on Linux servers, we need to regularly restart the server to release memory. For example, a netizen left a message and mentioned that he hopes to write a tutorial on automatically restarting the server. In fact, there are many such articles on the Internet. We can find them by searching casually. Most of them use crontab to execute commands regularly. Snail also looked through previous articles and it seems that the usage of this crontab command was not mentioned.
So, in this article, Snail will sort out in detail the functions that we may need to automatically restart the server regularly for VPS and server projects, and also use the crontab command method.
First, install Crontab
Generally, our servers are installed by default, and you can just perform the second step. However, some distributions are not installed, so we just install it first no matter what. If it is already installed or not, it doesn’t matter.
1. centos
yum install vixie-cron crontabschkconfig crond onservice crond start
2. debian
apt-get install cron/etc/init.d/cron restart
According to the environment of our server, crontab is installed and started.
Second, edit the scheduled automatic script
crontab -e
Execute the script in ssh and edit the file.
0 1 * * * /sbin/reboot
Putting in this script means restarting the server at 1 am every day. After editing: wq save and exit.
Third, save, exit and restart to take effect
/etc/rc.d/init.d/crond stop/etc/rc.d/init.d/crond start
This will take effect after execution, and can realize the function of automatically restarting the server at regular intervals that we need. In fact, the friend who said that you need to log in to the background to restart every day is also incorrect. We can directly log in to SSH and then perform a reboot. There is no need to log in to the website background and click its restart button as you said.
Recommended site search: Mainland China proxy IP, virtual host, high-defense server, Chinese domain name query, Hong Kong high-defense server rental independent IP space, Tencent cloud server, overseas virtual host, dual-line server hosting, ICP filing query system,
发表评论