Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS EC2 Ubuntu 14.04 instance clock running 12 minutes ahead

We are using Ubuntu 14.04 (LTS) on Amazon EC2 m4.xlarge instances. It seems the instance clock is running 12 minutes ahead of the current time.

I am using python shell to check time by running this command

import datetime; datetime.datetime.utcnow()

I was wondering if there is any solution to this issue that does not involve an instance restart.

Thanks

like image 401
Saurabh Jha Avatar asked Nov 25 '18 05:11

Saurabh Jha


People also ask

Does AWS use UTC time?

This service uses a fleet of satellite-connected and atomic reference clocks in each AWS Region to deliver accurate current time readings of the Coordinated Universal Time (UTC) global standard.

Why is my EC2 Linux instance down with an instance status check failure?

The instance status check failure indicates an issue with the reachability of the instance. This issue occurs due to operating system-level errors such as the following: Failure to boot the operating system. Failure to mount the volumes correctly.

Why does it take so long to stop EC2 instance?

Instances might appear "stuck" in the stopping state when there is a problem with the underlying hardware hosting the instance. This can also occur when hibernating a hibernation-enabled instance. Note: To check the most recent state of your instance, choose the refresh icon in the Amazon EC2 console.


1 Answers

You must edit the chrony configuration file to add a server entry for the Amazon Time Sync Service.

To configure your instance to use the Amazon Time Sync Service

  1. Connect to your instance and use apt to install the chrony package.

ubuntu:~$ sudo apt install chrony

Note

If necessary, update your instance first by running sudo apt update.

  1. Open the /etc/chrony/chrony.conf file using a text editor (such as vim or nano). Add the following line before any other server or pool statements that are already present in the file, and save your changes:

server 169.254.169.123 prefer iburst

  1. Restart the chrony service.

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

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

  1. [ ok ] Restarting chrony (via 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

In the output that's returned, ^* indicates the preferred time source.

  1. Verify the time synchronization metrics that are reported by 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
like image 78
rbashish Avatar answered Oct 17 '22 22:10

rbashish