我有一个Debain控制台专用系统。
我刚意识到这不是在更新它的时钟:
$ date
Mon 10 Aug 20:33:23 BST 2020
$ ntpdate
10 Aug 20:27:45 ntpdate[8029]: no servers can be used, exiting
$ ntpdate-debian
10 Aug 20:28:20 ntpdate[8038]: the NTP socket is in use, exiting
$ sudo ntpdate
10 Aug 20:33:53 ntpdate[8371]: no servers can be used, exiting
$ sudo ntpdate-debian
10 Aug 20:28:20 ntpdate[8038]: the NTP socket is in use, exiting
事实:
在我停止"ntp服务“之后:
$ sudo service ntp stop
$ sudo ntpdate
10 Aug 20:33:53 ntpdate[8371]: no servers can be used, exiting
$ sudo ntpdate-debian
1 Apr 17:25:24 ntpdate[8383]: step time server a.b.c.d offset 83278265.128578 sec
$ sudo service ntp start
如您所见,在停止ntp服务后,ntpdate
仍然无法运行,但ntpdate-debian
最终可以设置正确的日期。
如何更改下面的配置,让"ntp服务“在后台自动完成其工作?
driftfile /var/tmp/ntp/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
pool 0.europe.pool.ntp.org iburst
pool 1.europe.pool.ntp.org iburst
pool 2.europe.pool.ntp.org iburst
pool 3.europe.pool.ntp.org iburst
server 0.debian.pool.ntp.org
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
restrict 127.0.0.1
restrict ::1
restrict source notrap nomodify noquery
我的配置怎么了?它甚至包含"0.debian.pool.ntp.org",如果我手动运行它:
ntpdate -q 0.debian.pool.ntp.org
发布于 2023-04-01 15:24:25
您没有提到您的Debian版本,但它似乎是Debian 10 (buster
,目前的“旧版本”)或更高版本。自从NTP套件的主要开发人员(DavidL.Mills,84岁)退休后,NTP代码的状态就停滞不前了。
到Debian 11发布时,ntpdate
和ntpd
的最新上游版本都相当陈旧,并且存在一些已知的安全漏洞,因此Debian 11最终推荐了更新的NTP实现chrony
。然而,Debian 11中仍然有经典的ntpdate
和ntpd
。
/usr/sbin/ntpdate
使用的唯一配置文件是/etc/ntp.keys
。其他一切都必须在命令行上指定,或者在调用/usr/sbin/ntpdate
的脚本中指定。
ntpdate-debian
是一个读取/etc/default/ntpdate
并使用在那里配置的时间服务器的脚本。
/etc/ntp/ntp.conf
仅用于NTP服务( ntpd
进程)。
在没有任何其他参数的情况下,ntpdate
和sudo ntpdate
的失败似乎是正常的,而且是预期的,因为ntpdate
不知道在这样调用时使用哪台服务器(S)。
由于ntpdate
和ntpd
(= ntp服务)都试图使用本地UDP端口123,所以不能同时运行这两个端口:它必须是一个或另一个。这解释了为什么您的sudo ntpdate
只在停止NTP服务之后才能工作。由于UDP端口号小于1024,因此在没有根权限的情况下不能使用该端口。
您没有显示/etc/default/ntpdate
的内容,所以我猜不出它使用的是哪个服务器(S),但是在您停止NTP服务之后,它似乎已经工作了。在没有参数的情况下运行ntpdate
并不指定要使用哪个NTP服务器进行同步,即使使用sudo
也会出现故障。
NTP服务无法同步您的时钟,因为您的系统时间是完全错误的(几年!)默认情况下,NTP服务(= ntpd
进程)的安全限制为+/- 1000秒:如果系统时间超过这个值,ntpd
甚至不会尝试修复它,因为巨大的时间跳转会导致数据库和其他关心时间的软件出现问题。系统管理员将负责将系统时钟调整到与当前时间大致类似的位置,然后ntpd
将能够同步它。
如果ntpd
是用-g
选项启动的,则第一次调整(仅限于!)可以大于1000秒的安全限值。如果您的系统使用Debian10‘S默认值,/etc/default/ntp
应该有NTPD_OPTS='-g'
,这告诉ntpd
在作为服务启动时使用这个选项。如果您有此配置,那么只需停止并重新启动NTP服务(sudo service ntp stop; sudo service ntp start
)就足以解决您的时间问题。除非在ntpd
中有一些最终的健全检查,使它拒绝作出超过一年左右的调整。
(这种默认设置实际上会使Debian 10's NTP服务在运行时重新启动有点危险。其他发行版通过拥有两个独立的服务来解决这个问题:一个在启动早期运行的一次性ntpdate
服务,在需要时可以进行大的调整,然后ntpd
开始,只限于逐步调整;这使得ntpd
服务在任何时候重新启动都更安全。)
假设您的系统使用的是具有电池支持功能的实时时钟的类似PC的x86硬件( RTC,也是"BIOS时钟“),您也许应该在sudo ntpdate-debian
之后执行一次sudo hwclock --systohc --utc
,以使RTC达到正确的时间。如果系统运行精度不高,系统关闭时应将系统时间控制在ntpd
S的安全范围内,这样ntpd
才能完全同步。
发布于 2023-04-01 15:04:16
交叉检查要向其中添加服务器的配置文件。
ntpdate不使用“ntp.conf”。
另外,如果您已经运行了“ntpd”服务,则需要进行交叉检查。可能会制造冲突。
https://unix.stackexchange.com/questions/741678
复制