如何在Arch Linux中修复时间

我目前在我的桌面电脑上使用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

更新

当我运行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).

路由追踪

我还尝试了命令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  * * *

怎么修复这个问题?我甚至尝试了timedatectl set-ntp true。我需要重新启动电脑才能生效吗?

好工作。谷歌说Cyberoam是一种(网络过滤?)防火墙品牌。大学使用内部NTP服务器来为自己的计算机进行时间同步不是罕见的情况,您很可能可以访问这些服务器。(显然,使用Active Directory的Windows PC将使用域控制器作为NTP服务器)。我记得约克大学有一个非常相似的设置。不幸的是,我在IISC网站上找不到任何关于您的IT的文档。 - sourcejedi
1看起来 SERC 处理你们校园的 IT。他们有一些关于 Linux 的说明,虽然没有关于 NTP 的内容,也许你可以获得指引,找到能提供帮助的人?http://nitss.iisc.ac.in/ 和 http://www.serc.iisc.in/facilities/support/ - sourcejedi
@sourcejedi 非常感谢,您已经超出了SE答案所需的范围。 - SDG
systemd的GitHub上有一个相关的错误报告:由于dnssec导致时间不正确时无法同步时间 - Marc.2377
2个回答

systemd-timesyncd不需要您重新启动。我在我的系统上测试了timedatectl。可能需要等待一分钟进行连接。
man timedatectl
status 显示系统时钟和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

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

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

chronyc不同的是,没有记录任何关于如何额外查询systemd-timesyncd的方法...实际上,除了" NTP同步: 否"之外,希望有有用的日志!

我建议以下目标:

  1. 确定您的系统正在尝试使用哪个众所周知的pool.ntp.org别名。
  2. 测试别名,例如ntpdate -q arch.pool.ntp.org
  3. traceroute到别名,查看是否有附近的阻止访问的防火墙。与往常一样,我会首先使用ping,因为它可以更快地得到结果(并且不容易被误解),或者使用mtr版本的traceroute(这也默认为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


看一下上面的情况。我查询了sudo systemctl status systemd-timesyncd,似乎有一些timed-out的日志。现在我需要进行traceroute吗? - SDG
刚刚用了 traceroute 命令并得到了一些结果。我该如何将 tracerouteping 命令结合使用? - SDG
在我最新安装的Archlinux上,systemd-timesyncd.service没有运行。我启动并启用了它,现在我的机器时间是正确的。 - Waseem

你的时区设置正确吗?你应该通过 timedatectl set-timezone 命令来设置正确的时区。

date 命令显示的是系统时间,适用于你当前所在的位置。

ntpdate 命令将会校正你所在时区的时间。

例如,使用苹果的ntp服务器将会得到以下结果:

sudo ntpdate time.apple.com

11 Jan 19:18:28 ntpdate[1052]: adjust time server 17.253.38.125 offset 0.004981 sec

1时区无法修复"NTP同步:否"。 - sourcejedi