新聞中心
VPS定時重啟的方法

創(chuàng)新互聯(lián)公司是專業(yè)的杞縣網站建設公司,杞縣接單;提供成都做網站、成都網站制作,網頁設計,網站設計,建網站,PHP網站建設等專業(yè)做網站服務;采用PHP框架,可快速的進行杞縣網站開發(fā)網頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網站,專業(yè)的做網站團隊,希望更多企業(yè)前來合作!
方法一:使用crontab設置定時任務
步驟1:登錄VPS
使用SSH工具(如PuTTY、Xshell等)登錄到VPS。
步驟2:創(chuàng)建定時任務文件
在VPS上創(chuàng)建一個用于存放定時任務的文件,例如/etc/cron.d/reboot。
sudo touch /etc/cron.d/reboot
步驟3:編輯定時任務文件
使用文本編輯器(如vim、nano等)編輯剛剛創(chuàng)建的定時任務文件。
sudo vim /etc/cron.d/reboot
在文件中添加以下內容,表示每天凌晨3點執(zhí)行重啟命令:
0 3 * * * root reboot
保存并退出。
步驟4:重啟cron服務
為了讓新添加的定時任務生效,需要重啟cron服務。
sudo systemctl restart crond
方法二:使用systemd設置定時任務
步驟1:創(chuàng)建定時任務文件
在VPS上創(chuàng)建一個用于存放定時任務的systemd服務文件,例如/etc/systemd/system/reboot.service。
sudo touch /etc/systemd/system/reboot.service
步驟2:編輯定時任務文件
使用文本編輯器(如vim、nano等)編輯剛剛創(chuàng)建的定時任務文件。
sudo vim /etc/systemd/system/reboot.service
在文件中添加以下內容,表示每天凌晨3點執(zhí)行重啟命令:
[Unit] Description=Reboot at a specific time After=networkonline.target nsslookup.target [Service] Type=simple ExecStart=/sbin/shutdown r +0 User=root Group=root [Install] WantedBy=multiuser.target
保存并退出。
步驟3:啟動并啟用定時任務
啟動剛剛創(chuàng)建的定時任務,并將其設置為開機自啟。
sudo systemctl start reboot.service sudo systemctl enable reboot.service
至此,VPS已經設置了定時重啟。
本文題目:vps定時重啟的方法是什么
分享鏈接:http://www.fisionsoft.com.cn/article/ccojdgp.html


咨詢
建站咨詢
