How to Sync Time in Rocky Linux 8 using Chrony

Chrony is an implementation of the Network Time Protocol. It is used to synchronize the system clock from different NTP servers, reference clocks or via manual input. It runs on Unix-like operating systems and is released under the GNU GPL v2.

Install Chrony

Install Chrony using following command,

yum install chrony -y

Configuration File of Chrony

Configuration file for Chrony is /etc/chrony.conf. The file looks like below.

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
pool 2.pool.ntp.org iburst

# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3

# Enable kernel synchronization of the real-time clock (RTC).
rtcsync

# Enable hardware timestamping on all interfaces that support it.
#hwtimestamp *

# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2

# Allow NTP client access from local network.
#allow 192.168.0.0/16

# Serve time even if not synchronized to a time source.
#local stratum 10

# Specify file containing keys for NTP authentication.
keyfile /etc/chrony.keys

# Get TAI-UTC offset and leap seconds from the system tz database.
leapsectz right/UTC

# Specify directory for log files.
logdir /var/log/chrony

# Select which information is logged.
#log measurements statistics tracking

Testing Chrony

Let's sync time of our centOS server with the remote NTP server manually. You can get a list of NTP Servers from https://www.ntppool.org/en/ -- It is recommended to select a NTP server located closest to your server location.

chronyd -q 'server 0.europe.pool.ntp.org iburst'

Output:

[root@localhost ~]# chronyd -q 'server 0.europe.pool.ntp.org iburst'
2021-05-18T01:46:36Z chronyd version 3.5 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +SECHASH +IPV6 +DEBUG)
2021-05-18T01:46:36Z Initial frequency 0.747 ppm
2021-05-18T01:46:41Z System clock wrong by -0.000459 seconds (step)
2021-05-18T01:46:41Z chronyd exiting

In case you get an error during this command, please run service chronyd stop first.

Start and Enabled Chronyd Service

Start and enable chronyd using below command,

systemctl start chronyd

systemctl enable chronyd

Output:

[root@localhost ~]# systemctl start chronyd
[root@localhost ~]# systemctl enable chronyd
[root@localhost ~]# systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor pre>
   Active: active (running) since Mon 2021-05-17 21:49:22 EDT; 2s ago
     Docs: man:chronyd(8)
           man:chrony.conf(5)
  Process: 5321 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=ex>
  Process: 5317 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUC>
 Main PID: 5319 (chronyd)
    Tasks: 1 (limit: 4940)
   Memory: 836.0K
   CGroup: /system.slice/chronyd.service
           └─5319 /usr/sbin/chronyd

Verify and Track Chrony Synchronization

To verify whether your system’s time is synchronized using chrony.

chronyc tracking

Output:

[root@localhost ~]# chronyc tracking
  Reference ID    : A2F45310 (ntp1.applefan.org)
  Stratum         : 3
  Ref time (UTC)  : Tue May 18 01:49:29 2021
  System time     : 0.000000573 seconds fast of NTP time
  Last offset     : -0.000002838 seconds
  RMS offset      : 0.000002838 seconds
  Frequency       : 0.912 ppm fast
  Residual freq   : +31.256 ppm
  Skew            : 11.700 ppm
  Root delay      : 0.016285047 seconds
  Root dispersion : 0.008669009 seconds
  Update interval : 0.6 seconds
  Leap status     : Normal

From the above output,

  • Reference ID is the ID and name of server to which your system’s time currently synced.
  • Stratum , it indicates the number of hops away from the server with an attached reference clock we are.

Check Chrony Sources

List time sources used by chronyd.

chronyc sources

Output:

[root@localhost ~]# chronyc sources
210 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^[[A^- pegasus.latt.net              2   6    37    28    -19us[  -19us] +/-   50ms
^- clock.sjc.he.net              1   6    33    90  +2316us[+2316us] +/-   31ms
^- ns1.backplanedns.org          2   6   253    20  +2906us[+2906us] +/-  117ms
^* ntp1.applefan.org             2   6    17    93    +59us[  +56us] +/-   16ms

Check Chrony Source Statistics

List drift speed and offset estimation of each source that is used by chronyd.

chronyc sourcestats -v

Output:

[root@localhost ~]# chronyc sourcestats -v

210 Number of sources = 4
                             .- Number of sample points in measurement set.
                            /    .- Number of residual runs with same sign.
                           |    /    .- Length of measurement set (time).
                           |   |    /      .- Est. clock freq error (ppm).
                           |   |   |      /           .- Est. error in freq.
                           |   |   |     |           /         .- Est. offset.
                           |   |   |     |          |          |   On the -.
                           |   |   |     |          |          |   samples. \
                           |   |   |     |          |          |             |
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
==============================================================================
pegasus.latt.net            6   3   136     -0.182      4.455    -30us    74us
clock.sjc.he.net            4   3     8     +8.040     69.720  +3382us    13us
ns1.backplanedns.org        5   3    77    -17.244    364.014  +5435us   305us
ntp1.applefan.org           5   3   135     +0.570     12.945    +13us   105us

You have now successfully synced your Rocky Linux 8 time with Chrony.