Linux之系统时间同步

Posted ZONG_XP

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux之系统时间同步相关的知识,希望对你有一定的参考价值。

在 ubuntu 上开发时,发现系统时间与网络时间有偏差,毫无疑问,没有做网络校时,因此本文对相关的操作做一下记录。

首先查看系统时间问题,运行 date 指令,输出如下

首先安装相关工具

sudo apt-get install ntpdate

 然后运行 timedatectl 指令,输出如下

$ timedatectl
                      Local time: 二 2021-07-20 19:36:38 CST
                  Universal time: 二 2021-07-20 11:36:38 UTC
                        RTC time: 二 2021-07-20 11:37:55
                       Time zone: Asia/Shanghai (CST, +0800)
       System clock synchronized: no
systemd-timesyncd.service active: no
                 RTC in local TZ: no

可以看到 systemd-timesyncd.service 服务处于关闭状态,我们手动启动一下

$ sudo timedatectl set-ntp true

再次运行,可以看到时间已经同步

$ timedatectl
                      Local time: 二 2021-07-20 19:29:05 CST
                  Universal time: 二 2021-07-20 11:29:05 UTC
                        RTC time: 二 2021-07-20 11:29:05
                       Time zone: Asia/Shanghai (CST, +0800)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

目标达成!

以上是关于Linux之系统时间同步的主要内容,如果未能解决你的问题,请参考以下文章