How to Sync Time in Rocky Linux 8 using Chrony

Install Chrony on Rocky Linux

To Install Chrony on Rocky Linux by 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

we can use chronyd to sync time of our Rocky Linux server with remote NTP server manually.

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

To start and enable chronyd using following commands.

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

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

To list information about the current time sources that the chronyd is using.

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

To list the information about drift speed and offset estimation of each source that the chronyd is using.

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