配置校时服务

132 阅读1分钟

配置校时服务

安装ntpdate

sudo apt install ntpdate

手动校时

sudo ntpdate -u ntp.ntsc.ac.cn
  • -u:可越过防火墙与主机同步

  • ntp.ntsc.ac.cn:国家授时中心的服务地址

同步硬件时间

sudo hwclock -w

定时校时

校时脚本

vi ntp.sh

写入以下内容:

#!/bin/bash
/usr/sbin/ntpdate -u ntp.ntsc.ac.cn;
/usr/sbin/hwclock -w;

授予执行权限

chmod +x ntp.sh

创建定时任务

sudo crontab -e

加入以下内容:

*/30 * * * * /root/ntp.sh  # 表示每30分钟执行一次