Focus on cloud service provider activities
Notes on website operation and maintenance

Setting Method for Automatic Scheduled Restart of Linux Server CentOS/Debian Environment

Some of us need to restart the server regularly to release memory when operating projects in the Linux server, just like a netizen left a message saying that he hopes to write a tutorial on automatic server restart. In fact, there are many articles of this kind on the Internet, and we can find them by any search. Most of them use crontab to execute commands regularly. Lao Zuo also read the previous article and didn't seem to mention the usage of the crontab command.

 Setting Method for Automatic Scheduled Restart of Linux Server CentOS/Debian Environment

Therefore, in this article, Lao Zuo has organized in detail. We may need to implement the function of automatically restarting the server on a regular basis for VPS and projects in the server, and also use the crontab command.

First, install Crontab

Generally, our servers are installed by default, and the second step can be performed directly. However, some distributions are not installed, so no matter how we install them first, it doesn't matter if they are already installed or not.

1、centos

yum install vixie-cron crontabs
chkconfig crond on
service crond start

2、debian

apt-get install cron
/etc/init.d/cron restart

According to the environment of our server, install crontab and start it.

Second, edit timed automatic script

crontab -e

Execute the script in ssh, and then edit the file.

0 1 * * * /sbin/reboot

Throwing in this script means that the server is restarted at 1 am every day. After editing: wq save and exit.

Third, save, exit, restart and take effect

/etc/rc.d/init.d/crond stop
/etc/rc.d/init.d/crond start

After this is executed, it can take effect and achieve the function of automatically restarting the server on a regular basis that we need. In fact, the friend said that it is incorrect to log in to the background and restart every day. We can directly log in to SSH and then reboot. There is no need to log in to the website background and click his restart button.

Vote for you
Domain name host preferential information push QQ group: six hundred and twenty-seven million seven hundred and seventy-five thousand four hundred and seventy-seven Get preferential promotion from merchants.
Like( zero )
Do not reprint without permission: Lao Zuo's Notes » Setting Method for Automatic Scheduled Restart of Linux Server CentOS/Debian Environment


Scan the code to follow the official account

Get more news about webmaster circle!
Entrepreneurship, operation and new knowledge