我的时钟已关闭,因此我想使用ntpdate. 我尝试了几个不同的 NTP 服务器,但由于某种原因,我总是收到以下错误消息:
$ sudo ntpdate ntp.ubuntu.com
4 Mar 12:27:35 ntpdate[1258]: no server suitable for synchronization found
$ sudo ntpdate pool.ntp.org
4 Mar 12:27:50 ntpdate[1267]: no server suitable for synchronization found
$ sudo ntpdate de.pool.ntp.org
4 Mar 12:28:01 ntpdate[1273]: no server suitable for synchronization found
$ sudo ntpdate us.pool.ntp.org
4 Mar 12:28:12 ntpdate[1276]: no server suitable for synchronization found
Run Code Online (Sandbox Code Playgroud)
我查看了相关问题,但没有一个能解决我的问题:
ntpd守护进程的冲突。我根本没有安装这个ntp包(包括ntpd守护进程)。ntpdate命令将在引导时不正常工作的时候,他把它变成自己的/etc/rc.local,这个问题同样用一个冲突ntpd时正在运行后台进程。我既ntpdate不想在启动时运行,也不想(再次)ntpd安装守护进程。ntpd而不是ntpdate”。啊啊啊......并尝试使用ntpd守护程序而不是ntpdate实用程序。它也不会同步我的时间;守护进程启动正常,但我的时钟仍然关闭。我什至尝试使用/etc/ntp.conf后一篇文章中接受的答案中的确切答案,然后重新启动守护程序。不行。无论如何,我不想使用守护进程。我非常清楚这ntpdate被认为是“已弃用”,建议ntpd -q改用。另见此处:
但由于ntpd对我也不起作用,问题出在别处。而且我发现我宁愿不必为了同步时钟而安装任何额外的包。ntpdate预装了 Ubuntu,它应该可以正常工作。所以我又卸载了这个ntp包。
从这篇文章:
...我知道端口 123 可能在我工作场所的计算机/网络中被阻止。的确,
$ sudo nmap -p123 -sU -P0 localhost
...
PORT STATE SERVICE
123/udp closed ntp
...
$ sudo ufw allow 123/udp
Rules updated
Rules updated (v6)
$ sudo nmap -p123 -sU -P0 localhost
...
PORT STATE SERVICE
123/udp open ntp
...
Run Code Online (Sandbox Code Playgroud)
但仍然:
$ sudo ntpdate ntp.ubuntu.com
4 Mar 13:06:16 ntpdate[4361]: no server suitable for synchronization found
Run Code Online (Sandbox Code Playgroud)
即使有-u选项,它告诉ntpdate使用非特权端口进行同步(而不是 port 123),这肯定不会被我的工作场所阻止:
$ sudo ntpdate -u ntp.ubuntu.com
4 Mar 13:06:28 ntpdate[4427]: no server suitable for synchronization found
Run Code Online (Sandbox Code Playgroud)
最后,从这篇关于 serverfault 的帖子:
...我想可能是NTP服务器的层太高了。然而,他们不是。让我们看看更多的调试信息:
$ sudo ntpdate -dv ntp.ubuntu.com
4 Mar 13:12:24 ntpdate[4523]: ntpdate 4.2.6p5@1.2349-o Wed Oct 9 19:08:07 UTC 2013 (1)
Looking for host ntp.ubuntu.com and service ntp
host found : golem.canonical.com
transmit(91.189.89.199)
transmit(91.189.94.4)
transmit(91.189.89.199)
transmit(91.189.94.4)
transmit(91.189.89.199)
transmit(91.189.94.4)
transmit(91.189.89.199)
transmit(91.189.94.4)
transmit(91.189.89.199)
transmit(91.189.94.4)
91.189.89.199: Server dropped: no data
91.189.94.4: Server dropped: no data
server 91.189.89.199, port 123
stratum 0, precision 0, leap 00, trust 000
refid [91.189.89.199], delay 0.00000, dispersion 64.00000
transmitted 4, in filter 4
reference time: 00000000.00000000 Mon, Jan 1 1900 1:00:00.000
originate timestamp: 00000000.00000000 Mon, Jan 1 1900 1:00:00.000
transmit timestamp: d6c041ae.e6166441 Tue, Mar 4 2014 13:12:30.898
filter delay: 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
filter offset: 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000
delay 0.00000, dispersion 64.00000
offset 0.000000
server 91.189.94.4, port 123
stratum 0, precision 0, leap 00, trust 000
refid [91.189.94.4], delay 0.00000, dispersion 64.00000
transmitted 4, in filter 4
reference time: 00000000.00000000 Mon, Jan 1 1900 1:00:00.000
originate timestamp: 00000000.00000000 Mon, Jan 1 1900 1:00:00.000
transmit timestamp: d6c041af.1948fc50 Tue, Mar 4 2014 13:12:31.098
filter delay: 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
filter offset: 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000
delay 0.00000, dispersion 64.00000
offset 0.000000
4 Mar 13:12:33 ntpdate[4523]: no server suitable for synchronization found
Run Code Online (Sandbox Code Playgroud)
Pfeeewww...这是一个很长的,对不起。我难住了。有什么线索吗?
无论NTP服务器HOSTNAME的数字/etc/ntp.conf,而不管是否ntpd服务运行与否,每当我跑sudo ntpdate -u HOSTNAME,我得到no server suitable for synchronization found。当ntpd服务未运行时也是如此,我省略了该-u选项。当ntpd服务正在运行并且我省略该-u选项时,我反而得到the NTP socket is in use, exiting.
还:
$ timedatectl status
Local time: Wed 2014-03-05 13:11:54 CET
Universal time: Wed 2014-03-05 12:11:54 UTC
Timezone: Europe/Berlin (CET, +0100)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: no
Last DST change: DST ended at
Sun 2013-10-27 02:59:59 CEST
Sun 2013-10-27 02:00:00 CET
Next DST change: DST begins (the clock jumps one hour forward) at
Sun 2014-03-30 01:59:59 CET
Sun 2014-03-30 03:00:00 CEST
Run Code Online (Sandbox Code Playgroud)
但是这里的 UTC 时间不正确。现在 UTC 时间是11:11,不是12:11。
和:
$ sudo hwclock --show
Wed 05 Mar 2014 01:11:56 PM CET -0.625627 seconds
Run Code Online (Sandbox Code Playgroud)
dfc*_*dfc 61
您的托管服务提供商正在阻止 ntp 数据包。一些 ISP 已经实施了这种严厉的方法来应对 DDoS 攻击。您可以看到 ntpdate 正在从 ntpdate -vd 发送数据包:
transmit(91.189.94.4)
transmit(91.189.89.199)
transmit(91.189.94.4)
transmit(91.189.89.199)
Run Code Online (Sandbox Code Playgroud)
我会联系您的 ISP,询问他们是否阻止了外部 ntp 请求,以及他们是否有可用于时间同步的本地服务器。
还有一些更模糊的可能性,但很难将它们排除在外,因为您还没有从 syslog 中发布任何日志。
小智 57
这不是 ntp 答案,但是...
sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
Run Code Online (Sandbox Code Playgroud)
这个和这里的 curl 版本。
小智 16
使用 htpdate
如果您的网络阻止了 ntp 传输,请安装 htpdate。它通过 http 协议同步时间。根据手册页,精度将在 0.5 秒以内。
sudo apt-get install htpdate
sudo htpdate -a google.com
Run Code Online (Sandbox Code Playgroud)
htpdate 服务将在您安装软件包时启动。如果有互联网连接,时间将立即更新。
Sto*_*rux 12
我有同样的问题,这就是我解决它的方法。我已经从上到下给出了详细的答案。您可能想跳到我的答案的中间,或者只是参考下面的屏幕截图以一目了然。
首先安装ntpdate(显然你已经这样做了)
sudo apt-get install ntpdate
Run Code Online (Sandbox Code Playgroud)
NEXT需要用服务器配置ntp如下:
您至少应该在 /etc/ntp.conf 配置文件中设置以下参数:
server
例如,使用 nano 文本编辑器打开 /etc/ntp.conf 文件:
sudo nano /etc/ntp.conf
Run Code Online (Sandbox Code Playgroud)
找到服务器参数,如果它为空,请按如下方式设置:
server pool.ntp.org
Run Code Online (Sandbox Code Playgroud)
但通常在 ubuntu 中已经有一些服务器是预先编写的,这可能是
server 0.ubuntu.pool.ntp.org
server 1.ubuntu.pool.ntp.org
server 2.ubuntu.pool.ntp.org
server 3.ubuntu.pool.ntp.org
Run Code Online (Sandbox Code Playgroud)

然后保存文件并重新启动 ntpd 服务:
sudo /etc/init.d/ntpd start
Run Code Online (Sandbox Code Playgroud)
您可以使用以下命令立即将系统时钟同步到 NTP 服务器:
sudo ntpdate pool.ntp.org
Run Code Online (Sandbox Code Playgroud)
或者只是运行已经定义的服务器
sudo ntpdate 0.ubuntu.pool.ntp.org
Run Code Online (Sandbox Code Playgroud)
或使用 server 定义的其他服务器
一般来说
sudo ntpdate <one of the servername in /etc/ntp.conf>
Run Code Online (Sandbox Code Playgroud)
但在那之后,您可能会收到NTP socket in use如下所示的错误:

在这种情况下,只需运行
ntpdate -u pool.ntp.org
Run Code Online (Sandbox Code Playgroud)
在 ntp deamon 运行时更新
或者只是停止守护进程,更新并重新启动它,如下所示:
sudo ntpdate pool.ntp.org
sudo service ntp stop
sudo ntpdate pool.ntp.org
sudo service ntp start
Run Code Online (Sandbox Code Playgroud)
你会得到

小智 6
与亚历克斯的回答类似,这对我绕过被防火墙设置的 ntp 端口有用:
sudo date -s "$(curl http://s3.amazonaws.com -v 2>&1 | \
grep "Date: " | awk '{ print $3 " " $5 " " $4 " " $7 " " $6 " GMT"}')"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
320965 次 |
| 最近记录: |