AWS EC2 Ubuntu 14.04实例时钟比标准时间快12分钟

5
我们正在Amazon EC2 m4.xlarge实例上使用Ubuntu 14.04(LTS)。看起来实例时钟比当前时间快12分钟。
我使用Python shell运行以下命令来检查时间:
import datetime; datetime.datetime.utcnow()

我想知道是否有任何解决此问题的方案,而不涉及重新启动实例。
谢谢。
1个回答

6
您需要编辑chrony配置文件,为Amazon Time Sync Service添加服务器条目。 配置实例以使用Amazon Time Sync Service:
  1. 连接到您的实例并使用apt安装chrony软件包。

ubuntu:~$ sudo apt install chrony

注意: 如果需要,请先运行sudo apt update更新您的实例。
  1. 使用文本编辑器(如vimnano)打开/etc/chrony/chrony.conf文件。在文件中已经存在的任何其他服务器或池语句之前添加以下行,并保存更改:

server 169.254.169.123 prefer iburst

  1. 重新启动chrony服务。

ubuntu:~$ sudo /etc/init.d/chrony restart

[ ok ] Restarting chrony (via systemctl): chrony.service.

  1. [ ok ] 重新启动chrony(通过systemctl):chrony.service

ubuntu:~$ chronyc sources -v

 210 Number of sources = 7

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* 169.254.169.123               3   6    17    12    +15us[  +57us] +/-  320us
^- tbag.heanet.ie                1   6    17    13  -3488us[-3446us] +/- 1779us
^- ec2-12-34-231-12.eu-west-     2   6    17    13   +893us[ +935us] +/- 7710us
^? 2a05:d018:c43:e312:ce77:6     0   6     0   10y     +0ns[   +0ns] +/-    0ns
^? 2a05:d018:d34:9000:d8c6:5     0   6     0   10y     +0ns[   +0ns] +/-    0ns
^? tshirt.heanet.ie              0   6     0   10y     +0ns[   +0ns] +/-    0ns
^? bray.walcz.net                0   6     0   10y     +0ns[   +0ns] +/-    0ns

在返回的输出中,^*表示首选时间源。
5. 验证由chrony报告的时间同步指标。 ubuntu:~$ chronyc tracking
Reference ID    : 169.254.169.123 (169.254.169.123)
Stratum         : 4
Ref time (UTC)  : Wed Nov 29 07:41:57 2017
System time     : 0.000000011 seconds slow of NTP time
Last offset     : +0.000041659 seconds
RMS offset      : 0.000041659 seconds
Frequency       : 10.141 ppm slow
Residual freq   : +7.557 ppm
Skew            : 2.329 ppm
Root delay      : 0.000544 seconds
Root dispersion : 0.000631 seconds
Update interval : 2.0 seconds
Leap status     : Normal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接