如何在 Arch Linux 中修复时间

SDG*_*SDG 6 arch-linux terminal date time

我目前在我的桌面上使用 Arch Linux 作为我的操作系统。当我看我的时间时,是22:38,而时间显然是17:08左右。当我调用命令时timedatectl,我得到:

Local time: Wed 2017-01-11 22:37:43 IST
Universal time: Wed 2017-01-11 17:07:43 UTC
    RTC time: Wed 2017-01-11 17:07:41
    Time zone: Asia/Kolkata (IST, +0530)
Network time on: yes
NTP synchronized: no
RTC in local TZ: no
Run Code Online (Sandbox Code Playgroud)

更新

当我运行时sudo systemctl status systemd-timesyncd,我得到:

? systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/usr/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2017-01-11 00:49:36 IST; 1 day 1h ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 31123 (systemd-timesyn)
   Status: "Idle."
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/systemd-timesyncd.service
           ??31123 /usr/lib/systemd/systemd-timesyncd

Jan 12 01:39:42 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 5.9.78.71:123 (1.arch.pool.ntp.org).
Jan 12 01:39:53 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 192.53.103.108:123 (1.arch.pool.ntp.org).
Jan 12 01:40:03 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 139.59.19.184:123 (2.arch.pool.ntp.org).
Jan 12 01:40:13 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 139.59.45.40:123 (2.arch.pool.ntp.org).
Jan 12 01:40:24 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 123.108.200.124:123 (2.arch.pool.ntp.org).
Jan 12 01:40:34 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 125.62.193.121:123 (2.arch.pool.ntp.org).
Jan 12 01:40:44 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 139.59.45.40:123 (3.arch.pool.ntp.org).
Jan 12 01:40:55 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 123.108.200.124:123 (3.arch.pool.ntp.org).
Jan 12 01:41:05 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 139.59.19.184:123 (3.arch.pool.ntp.org).
Jan 12 01:41:15 sharan-pc systemd-timesyncd[31123]: Timed out waiting for reply from 125.62.193.121:123 (3.arch.pool.ntp.org).
Run Code Online (Sandbox Code Playgroud)

跟踪路由

我也试过命令traceroute -U -p ntp pool.ntp.org,我得到:

traceroute to pool.ntp.org (139.59.19.184), 30 hops max, 60 byte packets
 1  10.114.1.1 (10.114.1.1)  1.713 ms  2.020 ms  2.343 ms
 2  10.10.2.41 (10.10.2.41)  1.123 ms  2.580 ms  2.836 ms
 3  cyberoam.iisc.ac.in (10.10.1.98)  0.553 ms  0.806 ms  0.813 ms
 4  * * *
 5  * * *
 6  * * *
 7  * * *
 8  * * *
 9  * * *
10  * * *
11  * * *
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *
Run Code Online (Sandbox Code Playgroud)

我该如何解决?我什至尝试过timedatectl set-ntp true。我应该重新启动才能生效吗?

sou*_*edi 5

systemd-timesyncd 不需要您重新启动。我已经在我的系统上测试了 timedatectl。连接可能需要等待一分钟。

man timedatectl

地位

显示系统时钟和 RTC 的当前设置,包括是否开启网络时间同步。注意网络时间同步是否开启只是反映了 systemd-timesyncd.service 单元是否开启。即使此命令显示状态为关闭,不同的服务仍可能将时钟与网络同步。

$ timedatectl status
      Local time: Wed 2017-01-11 13:45:07 GMT
  Universal time: Wed 2017-01-11 13:45:07 UTC
        RTC time: Wed 2017-01-11 13:45:07
       Time zone: Europe/London (GMT, +0000)
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: yes
Run Code Online (Sandbox Code Playgroud)

timedatectl 联机帮助页位于我的系统上。可能该实现是由 Fedora 修补的,而没有修补联机帮助页。我不知道如何查询使用的是哪个服务;我的系统碰巧使用了chronyd。我想也可以使用 ntp/ntpd。

但是,在您的情况下,我非常有信心 Arch 使用 timesyncd 的上游默认值。

$ systemctl status systemd-timesyncd
? systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/usr/lib/systemd/system/systemd-timesyncd.service; disabled; 
   Active: inactive (dead)
     Docs: man:systemd-timesyncd.service(8)

$ systemctl status chronyd
? chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor pres
   Active: active (running) since Mon 2017-01-09 19:09:39 GMT; 1 day 18h ago
 Main PID: 928 (chronyd)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/chronyd.service
           ??928 /usr/sbin/chronyd
Run Code Online (Sandbox Code Playgroud)

您可能在状态下记录了错误。确保以有权systemctl访问系统日志的用户身份运行,例如使用sudo.

与 chronyd with 不同,除了“NTP 同步:否”之外chronyc,没有记录的方法可以额外查询systemd-timesyncd......任何真正的东西。希望它有有用的日志!

我建议瞄准

  1. 确定pool.ntp.org您的系统正在尝试使用哪个众所周知的别名。
  2. 测试别名,例如ntpdate -q arch.pool.ntp.org.
  3. traceroute到别名以查看附近是否有阻止访问的阻止,即防火墙。与往常一样,我会ping首先使用,因为它可以更快地获得结果(并且不太容易被误解),或者使用mtrtraceroute的版本(这也默认为 ICMP traceroute,从而避免了来自多路径网络的大量输出)。最终你想要类似的东西traceroute -U -p ntp pool.ntp.org,即使用与 NTP 相同的 UDP 端口。

编辑:此答案的先前版本对 systemd-timesyncd 的默认 NTP 服务器感到困惑。尽管它们在 中被注释掉(禁用)timesyncd.conf,但只有在需要更改服务器时才需要取消注释该行。默认值在编译时内置到 timesyncd 中。所有文档中都提到了这一点。

https://www.cyberciti.biz/faq/linux-unix-bsd-is-ntp-client-working/

https://wiki.archlinux.org/index.php/Systemd-timesyncd