从其它平台迁移而来


安装ntpdate

1
sudo apt install ntpdate

手动校时

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

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

同步硬件时间

1
sudo hwclock -w

定时校时

校时脚本

1
vi ntp.sh

写入以下内容:

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

授予执行权限

1
chmod +x ntp.sh

创建定时任务

1
sudo crontab -e

加入以下内容:

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