如何在 Arch Linux 中修复时间

如何在 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。我需要重新启动才能生效吗?

答案1

systemd-timesyncd 不需要您重新启动。我已经在我的系统上测试了 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

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.

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

我建议瞄准

  1. pool.ntp.org确定您的系统正在尝试使用哪个众所周知的别名。
  2. 测试别名,例如ntpdate -q arch.pool.ntp.org
  3. traceroute查看别名以查看附近是否存在阻止访问的块,即防火墙。与往常一样,我会ping首先使用,因为它可以更快地获得结果(并且不太容易产生误解),或者使用mtr跟踪路由的版本(这也默认为 ICMP 跟踪路由,这可以避免多路径网络的大量输出)。最终您想要类似的东西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

答案2

您所在位置的时区是否正确?你应该通过 timedatectl set-timezone 设置正确的时区

日期命令正在显示您当前位置的系统时间。

日期将根据您的时区校正时间。

例如使用苹果 ntp 服务器将导致:

sudo ntpdate time.apple.com

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

相关内容