为什么时间不同步?

为什么时间不同步?

我希望时间同步,但同步不上。我尝试运行以下命令,但仍然无法同步。

# timedatectl set-ntp off
# timedatectl set-ntp on
# timedatectl status
                      Local time: Fri 2021-08-06 20:01:43 EDT
                  Universal time: Sat 2021-08-07 00:01:43 UTC
                        RTC time: Fri 2021-08-06 20:01:43
                       Time zone: America/New_York (EDT, -0400)
       System clock synchronized: no
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

编辑:更多信息

systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2021-08-07 15:26:10 EDT; 58min ago
     Docs: man:systemd-timesyncd.service(8)
  Process: 9351 ExecStart=/lib/systemd/systemd-timesyncd (code=exited, status=238/STATE_DIRECTORY)
 Main PID: 9351 (code=exited, status=238/STATE_DIRECTORY)


# journalctl -u systemd-timesyncd
1]: systemd-timesyncd.service: Service has no hold-off time, scheduling restart.
1]: systemd-timesyncd.service: Scheduled restart job, restart counter is at 5.
1]: Stopped Network Time Synchronization.
1]: systemd-timesyncd.service: Start request repeated too quickly.
1]: systemd-timesyncd.service: Failed with result 'exit-code'.
1]: Failed to start Network Time Synchronization.

运行 Ubuntu 18.04。互联网正常运行并可以浏览互联网。

答案1

显然存在目录权限错误,并且影响多个发行版。解决方案很简单。

$ sudo chmod 0700 /var/lib/private
$ sudo systemctl restart systemd-timesyncd
$ sudo timedatectl status

此外,这可能需要也可能不需要:

$ sudo rm -r /var/lib/private/systemd

来源: https://bbs.archlinux.org/viewtopic.php?id=233277

答案2

  1. 检查 /etc/ntp.conf 中的 ntp 配置

$ cat /etc/ntp.conf

...
pool 0.ubuntu.pool.ntp.org iburst 
pool 1.ubuntu.pool.ntp.org iburst 
pool 2.ubuntu.pool.ntp.org iburst 
pool 3.ubuntu.pool.ntp.org iburst 

如果必要的话编辑文件(nano /etc/ntp.conf

  1. 运行以下命令重启服务

sudo service ntp restart

  1. 最后,如果您的系统上启用了 UFW 防火墙,则需要打开 NTP UDP 端口 123 以接收传入连接:

$ sudo ufw allow from any to any port 123 proto udp

答案3

检查日志:journalctl -u systemd-timesyncd

我的问题与根距离参数有关(我的 Windows Server 同步服务器不好)。将 RootDistanceMaxSec 从默认值 5 增加到 15 解决了我的问题。

https://www.freedesktop.org/software/systemd/man/timesyncd.conf.html

相关内容