linux如何同步时间

同步时区
  • timedatectl list-timezones 列出所有时区
  • timedatectl set-local-rtc 1 将硬件时钟调整为与本地时钟一致, 0 为设置为 UTC 时间
  • timedatectl set-timezone Asia/Shanghai 设置系统时区为上海
    or
  • cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
将系统时间和网络时间同步
  • ntpdate 0.cn.pool.ntp.org
定时同步网络时间
  • vim /etc/crontab
    10 5 * * * root (/usr/sbin/ntpdate 0.cn.pool.ntp.org && /sbin/hwclock -w) &> /var/log/ntpdate.log
    每天的5点10分crontab运行一次命令,自动同步时间。

你可能感兴趣的:(linux如何同步时间)