AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[systemd-timesyncd](server)

Martin Hope
frankfalse
Asked: 2022-09-30 05:12:59 +0800 CST

systemd-timesyncd 的默认 NTP 服务器是什么?

  • -1

在我的 yocto 发行版中启用了该服务systemd-timesyncd.service。其配置文件(timesyncd.conf)如下:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See timesyncd.conf(5) for details.

[Time]
#NTP=
#FallbackNTP=time1.google.com time2.google.com time3.google.com time4.google.com
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048

如您所见,NTP未设置配置文件的选项。尽管如此,服务设置了系统日期,并且通过一些登录journalctl,我看到 NTP 服务器可能是time1.google.com.

我的问题是:NTP 服务器在哪里设置systemd-timesyncd?

谢谢

systemd-timesyncd
  • 1 个回答
  • 46 Views
Martin Hope
skwokie
Asked: 2021-05-29 22:09:13 +0800 CST

“systemd-timesyncd:网络配置已更改,尝试建立连接”是什么意思?

  • 1

我正在尝试调试一些网络连接问题,我看到:

systemd-timesyncd: Network configuration changed, trying to establish connection.

在系统日志中。我试图用谷歌搜索它,但我找不到一个好的定义。这是我需要担心的事情吗?配置更改是否仅在 的上下文中timesyncd?谢谢。

ubuntu-18.04 systemd-timesyncd
  • 2 个回答
  • 2184 Views
Martin Hope
Martin Melka
Asked: 2021-05-22 05:40:57 +0800 CST

systemd-timesyncd 需要打开传入的临时端口

  • 3

我正在尝试为 Ubuntu 服务器配置某种时间同步。服务器位于云提供商无状态防火墙后面。通过反复试验,我发现为了ntp工作,我必须打开传入的 UDP 端口 123。

然后我读到systemd-timesyncd现在首选使用,所以我尝试切换到那个。但这没有用。服务日志充满了

systemd-timesyncd[2656121]: Timed out waiting for reply from 91.189.89.199:123 (ntp.ubuntu.com).
systemd-timesyncd[2656121]: Timed out waiting for reply from 91.189.94.4:123 (ntp.ubuntu.com).

只有在我也将防火墙中的临时 UDP 端口列入白名单之后,32768–65535这才开始起作用:

systemd-timesyncd[2656121]: Initial synchronization to time server 91.189.91.157:123 (ntp.ubuntu.com).

是否真的需要打开该范围的端口才能运行systemd-timesync?


编辑以回应@Jesus-Loves-You 在下面的回复。更高的端口应该不是必需的,但在我的情况下,出于某种原因,它们显然是必需的。查看服务日志systemd-timesync(由我用 注释#):

# Before I enabled the 32786+ ports
May 21 11:49:21 myhost systemd-timesyncd[2656121]: Timed out waiting for reply from 91.189.89.198:123 (ntp.ubuntu.com).

# After I enabled the ports
May 21 11:49:06 myhost systemd-timesyncd[2656121]: Initial synchronization to time server 91.189.91.157:123 (ntp.ubuntu.com).

# After I disabled them again. Note that there are no log entries inbetween for almost
# three days. This, imo, pretty much proves that the ports are required.
May 24 09:29:34 myhost systemd-timesyncd[2656121]: Timed out waiting for reply from 91.189.91.157:123 (ntp.ubuntu.com).

有关港口的更多信息:

root@host:/# netstat -ulpvn | grep systemd
udp        0      0 127.0.0.53:53           0.0.0.0:*                           2218041/systemd-res
udp        0      0 0.0.0.0:42212           0.0.0.0:*                           2656121/systemd-tim

看起来42212是服务期望通信发生的端口。但几分钟后,当下一次轮询发生时:

root@host:/# netstat -ulpvn | grep systemd
udp        0      0 127.0.0.53:53           0.0.0.0:*                           2218041/systemd-res
udp        0      0 0.0.0.0:37240           0.0.0.0:*                           2656121/systemd-tim

现在端口变了。几分钟后,它再次变为51120。因此,我得出结论,该服务每次尝试同步时都会尝试在随机端口上进行通信。

firewall port systemd-timesyncd
  • 3 个回答
  • 1775 Views
Martin Hope
Stonecraft
Asked: 2020-07-11 05:48:16 +0800 CST

Ubuntu 20.04 时间同步问题和可能不正确的状态信息

  • 5

我在我的 KVM 主机(Lubuntu 20.04)上遇到了一些崩溃问题,在进行故障排除时,我注意到了一些与时间相关的错误。

经过进一步调查,令我惊恐的是,我发现时间没有同步。我确定它是以前设置的,我不知道它是如何变为未设置的。

admin@virtland:~$ sudo timedatectl
[sudo] password for admin: 
               Local time: Fri 2020-07-10 09:14:14 EDT  
           Universal time: Fri 2020-07-10 13:14:14 UTC  
                 RTC time: Fri 2020-07-10 13:14:14      
                Time zone: America/New_York (EDT, -0400)
System clock synchronized: no                           
              NTP service: n/a                          
          RTC in local TZ: no                           
admin@virtland:~$ 

我找到了这个线程并尝试了最佳答案,但无济于事。 https://askubuntu.com/questions/929805/timedatectl-ntp-sync-cannot-set-to-yes

admin@virtland:~$ sudo systemctl stop ntp
admin@virtland:~$ sudo ntpd -gq
10 Jul 09:17:57 ntpd[34358]: ntpd [email protected] (1): Starting
10 Jul 09:17:57 ntpd[34358]: Command line: ntpd -gq
10 Jul 09:17:57 ntpd[34358]: proto: precision = 0.070 usec (-24)
10 Jul 09:17:57 ntpd[34358]: leapsecond file ('/usr/share/zoneinfo/leap-seconds.list'): good hash signature
10 Jul 09:17:57 ntpd[34358]: leapsecond file ('/usr/share/zoneinfo/leap-seconds.list'): loaded, expire=2020-12-28T00:00:00Z last=2017-01-01T00:00:00Z ofs=37
10 Jul 09:17:57 ntpd[34358]: Listen and drop on 0 v6wildcard [::]:123
10 Jul 09:17:57 ntpd[34358]: Listen and drop on 1 v4wildcard 0.0.0.0:123
10 Jul 09:17:57 ntpd[34358]: Listen normally on 2 lo 127.0.0.1:123
10 Jul 09:17:57 ntpd[34358]: Listen normally on 3 enp6s0 10.0.0.18:123
10 Jul 09:17:57 ntpd[34358]: Listen normally on 4 lo [::1]:123
10 Jul 09:17:57 ntpd[34358]: Listen normally on 5 enp6s0 [fe80::7285:c2ff:fe65:9f19%3]:123
10 Jul 09:17:57 ntpd[34358]: Listening on routing socket on fd #22 for interface updates
10 Jul 09:17:58 ntpd[34358]: Soliciting pool server 209.50.63.74
10 Jul 09:17:59 ntpd[34358]: Soliciting pool server 4.53.160.75
10 Jul 09:18:00 ntpd[34358]: Soliciting pool server 69.89.207.199
10 Jul 09:18:00 ntpd[34358]: Soliciting pool server 72.30.35.88
10 Jul 09:18:01 ntpd[34358]: Soliciting pool server 173.0.48.220
10 Jul 09:18:01 ntpd[34358]: Soliciting pool server 162.159.200.1
10 Jul 09:18:01 ntpd[34358]: Soliciting pool server 108.61.73.243
10 Jul 09:18:02 ntpd[34358]: Soliciting pool server 208.79.89.249
10 Jul 09:18:02 ntpd[34358]: Soliciting pool server 208.67.75.242
10 Jul 09:18:02 ntpd[34358]: Soliciting pool server 91.189.94.4
10 Jul 09:18:03 ntpd[34358]: Soliciting pool server 91.189.89.198
10 Jul 09:18:03 ntpd[34358]: Soliciting pool server 67.217.112.181
10 Jul 09:18:04 ntpd[34358]: Soliciting pool server 91.189.89.199
10 Jul 09:18:04 ntpd[34358]: Soliciting pool server 64.225.34.103             
10 Jul 09:18:05 ntpd[34358]: Soliciting pool server 91.189.91.157             
10 Jul 09:18:06 ntpd[34358]: Soliciting pool server 2001:67c:1560:8003::c8    
10 Jul 09:18:06 ntpd[34358]: ntpd: time slew +0.001834 s                      
ntpd: time slew +0.001834s                                                    
admin@virtland:~$ sudo service ntp start                                       
admin@virtland:~$ sudo timedatectl                             
               Local time: Fri 2020-07-10 09:18:21 EDT                        
           Universal time: Fri 2020-07-10 13:18:21 UTC                        
                 RTC time: Fri 2020-07-10 13:18:21                            
                Time zone: America/New_York (EDT, -0400)                      
System clock synchronized: no                                                 
              NTP service: n/a                                                
          RTC in local TZ: no                                                 
admin@virtland:~$                  

我想也许我需要使用一些最新的指令,所以我尝试了这个: https ://linuxconfig.org/how-to-sync-time-on-ubuntu-20-04-focal-fossa-linux

admin@virtland:~$ timedatectl set-ntp off
Failed to set ntp: NTP not supported                                          
admin@virtland:~$ timedatectl set-ntp on
Failed to set ntp: NTP not supported                                          

然后我从另一个线程尝试了这个:

admin@virtland:~$ sudo systemctl status systemd-timesyncd.service
[sudo] password for admin: 
● systemd-timesyncd.service
     Loaded: masked (Reason: Unit systemd-timesyncd.service is masked.)
     Active: inactive (dead)

我从未接触过 timesyncd.conf,但无论如何它都被完全注释掉了:

cat /etc/systemd/timesyncd.conf                         
#  This file is part of systemd.                                              
#                                                                             
#  systemd is free software; you can redistribute it and/or modify it         
#  under the terms of the GNU Lesser General Public License as published by   
#  the Free Software Foundation; either version 2.1 of the License, or        
#  (at your option) any later version.                                        
#                                                                             
# Entries in this file show the compile time defaults.                        
# You can change settings by editing this file.                               
# Defaults can be restored by simply deleting this file.                      
#                                                                             
# See timesyncd.conf(5) for details.                                          
                                                                              
[Time]                                                                        
#NTP=                                                                         
#FallbackNTP=ntp.ubuntu.com                                                   
#RootDistanceMaxSec=5                                                         
#PollIntervalMinSec=32                                                        
#PollIntervalMaxSec=2048 

我再次检查了 timedatectl,现在它打开了,但仍然没有使用 NTP。我知道 NTP 更精确,这在某些情况下可能很重要。不确定带有 pci 直通的虚拟化是否需要非常精确的时间。

从我正在阅读的其他内容中,我认为 NTP 可能与 timesyncd 冲突。所以暂时去掉ntp:

sudo systemctl stop ntp
sudo apt-get purge ntp

但在清除 ntp 后,NTP 显示为活动状态!

admin@virtland:~$ timedatectl
               Local time: Fri 2020-07-10 09:34:52 EDT  
           Universal time: Fri 2020-07-10 13:34:52 UTC  
                 RTC time: Fri 2020-07-10 13:34:52      
                Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes                          
              NTP service: active                       
          RTC in local TZ: no     

我要疯了吗?NTP 是否还在这里?没有。

admin@virtland:~$ sudo systemctl start ntp
Failed to start ntp.service: Unit ntp.service not found.

很抱歉没有提出更集中的问题,但这里到底发生了什么?

我很好,真的迷路了。另外,我稍后会编辑这篇文章,并就删除 NTP(并因此激活它?!)是否解决了导致我陷入这个兔子洞的稳定性问题做出了一个不回答。

编辑:我做的下一件事是在 timesyncd 上禁用 ntp 并(重新)安装 NTP,如此处所述。https://www.digitalocean.com/community/tutorials/how-to-set-up-time-synchronization-on-ubuntu-18-04

结果是:

admin@virtland:~$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.us.pool.ntp.o .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.us.pool.ntp.o .POOL.          16 p    -   64    0    0.000    0.000   0.000
 2.us.pool.ntp.o .POOL.          16 p    -   64    0    0.000    0.000   0.000
 3.us.pool.ntp.o .POOL.          16 p    -   64    0    0.000    0.000   0.000
 0.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 2.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 3.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 ntp.ubuntu.com  .POOL.          16 p    -   64    0    0.000    0.000   0.000
admin@virtland:~$ timedatectl
               Local time: Fri 2020-07-10 10:35:39 EDT  
           Universal time: Fri 2020-07-10 14:35:39 UTC  
                 RTC time: Fri 2020-07-10 14:35:40      
                Time zone: America/New_York (EDT, -0400)
System clock synchronized: no                                                 
              NTP service: n/a                                                
          RTC in local TZ: no                                                 
admin@virtland:~$ systemctl status systemd-timesyncd 
● systemd-timesyncd.service                                                   
     Loaded: masked (Reason: Unit systemd-timesyncd.service is masked.)       
     Active: inactive (dead)                                                  
admin@virtland:~$ nano /etc/ntp.conf
admin@virtland:~$ systemctl status systemd-timesyncd                           
● systemd-timesyncd.service                                                   
     Loaded: masked (Reason: Unit systemd-timesyncd.service is masked.)       
     Active: inactive (dead)                                                  
admin@virtland:~$ ntpstat
unsynchronised                                                                
   polling server every 8 s 

我按照 Michael Hampton 的建议撤销了这些更改:这是否意味着它正在工作?

boss@virtland:~$ sudo systemctl stop ntp
Failed to stop ntp.service: Unit ntp.service not loaded.
boss@virtland:~$ sudo timedatectl set-ntp yes
boss@virtland:~$ sudo timedatectl set-ntp on
boss@virtland:~$ ntpq -p
bash: /usr/bin/ntpq: No such file or directory
boss@virtland:~$ systemctl status systemd-timesyncd 
● systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; >
     Active: active (running) since Fri 2020-07-10 10:49:18 EDT; 50s ago
       Docs: man:systemd-timesyncd.service(8)
   Main PID: 108365 (systemd-timesyn)
     Status: "Initial synchronization to time server 91.189.94.4:123 (ntp.ubu>
      Tasks: 2 (limit: 154317)
     Memory: 1.8M
     CGroup: /system.slice/systemd-timesyncd.service
             └─108365 /lib/systemd/systemd-timesyncd

Jul 10 10:49:17 virtland systemd[1]: Starting Network Time Synchronization...
Jul 10 10:49:18 virtland systemd[1]: Started Network Time Synchronization.
Jul 10 10:49:18 virtland systemd-timesyncd[108365]: Initial synchronization t>
lines 1-14/14 (END)
 timedatectl
               Local time: Fri 2020-07-10 10:52:56 EDT  
           Universal time: Fri 2020-07-10 14:52:56 UTC  
                 RTC time: Fri 2020-07-10 14:52:56      
                Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes                          
              NTP service: active                       
          RTC in local TZ: no            

所以我想它正在工作。由于让我走上这条道路的崩溃仍在发生,我想时间不是问题。

ubuntu ntp time-synchronization systemd-timesyncd
  • 1 个回答
  • 30420 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve