上一篇 下一篇 分享链接 返回 返回顶部

linux云服务器设置定时重启

发布人:欢子 发布时间:2026-01-21 12:28 阅读量:11
Linux定时重启vps服务器

1、首先创建一个新的systemd服务,这里创建的是reboot.service:touch/etc/systemd/system/reboot.service

2、然后编辑文件:vi/etc/systemd/system/reboot.service

3、在文件输入以下内容,保存退出:[Unit]

Description=RebootService

[Service]

Type=oneshot

ExecStart=/sbin/reboot

[Install]

WantedBy=multi-user.target

4、创建一个新的systemd定时器,这里创建的是reboot.timer:touch/etc/systemd/system/reboot.timer

5、然后编辑文件:vi/etc/systemd/system/reboot.timer

6、在文件输入以下内容,保存退出:

[Unit]

Description=RebootTimer

[Timer]

OnCalendar=*-*-*09:00:00

[Install]

WantedBy=timers.target

注意:注意OnCalendar的:***09:00:00,其中第一个表示星期,第二个表示月份,第三个表示日期,后面的时间格式是小时:分钟:秒。

这里设置的是每天上午9点重启的。

7、启用并启动定时器:systemctlenable--nowreboot.timer

设置完之后,就可以在每天的上午9点重启服务器了。

目录结构
全文