How to sync date time using Crony on CentOS 9 Stream / RHEL 9

How to sync date time using Crony on CentOS 9 Stream / RHEL 9

On CentOS 7, to sync date time we often use NTPD. But on CentOS 9, there is no NTPD from CentOS.

chrony and ntpd are two different implementations of the Network Time Protocol (NTP).

chrony is a newer implementation, work well in a wider range of conditions. It can usually synchronise the system clock faster and with better time accuracy. It has many features, but it does not implement some of the less useful NTP modes like broadcast client or multicast server/client.

If your computer is connected to the Internet only for few minutes at a time, the network connection is often congested, you turn your computer off or suspend it frequently, the clock is not very stable (e.g. there are rapid changes in the temperature or it is a virtual machine), or you want to use NTP on an isolated network with no hardware reference clocks in sight, chrony will probably work better for you.

You can read more about Crony on Crony documentation.

By default, chronyd does not operate as an NTP server. We need to add an allow directive to the chrony.conf file in order for chronyd to open the server NTP port and respond to client requests. For example as NTP server for internal network 192.168.1.0/24.

allow 192.168.1.0/24

Installing Crony on CentOS 9 / RHEL 9

To Install Chrony use the command below:

dnf install chrony

Then you can check Pool Server on /etc/chrony.conf

vi /etc/chrony.conf

Make a change on pool if you want to use different NTP server

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

Start Crony and enable on boot or system start up

To start and enable cronyd on system start up use command below:

systemctl enable --now chronyd

Or you can use 2 separated command:

systemctl start cronyd
systemctl enable cronyd

How to check synchronization of system time?

We need to check synchronization of system time using chrony with command:

chronyc tracking

Example output:

# chronyc tracking
Reference ID    : A29FC87B (time.cloudflare.com)
Stratum         : 4
Ref time (UTC)  : Sun Jun 11 07:51:09 2023
System time     : 0.000006475 seconds fast of NTP time
Last offset     : +0.000014262 seconds
RMS offset      : 0.000086579 seconds
Frequency       : 27.485 ppm fast
Residual freq   : +0.001 ppm
Skew            : 0.063 ppm
Root delay      : 0.018627709 seconds
Root dispersion : 0.002041860 seconds
Update interval : 1026.9 seconds
Leap status     : Normal

How to check NTP server from Cronyd

We can check NTP server / source using command below:

chronyc sources

Example output:

# chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^- ip148.ip-15-204-21.us         2  10   377  1038  -3044us[-3030us] +/-   75ms
^* time.cloudflare.com           3  10   377   993    -99us[  -85us] +/-   10ms
^+ pluto1.plutomail.io           2  10   377   333   -177us[ -177us] +/-   23ms
^- nu.binary.net                 2  10   377   578   +622us[ +622us] +/-   34ms

And to check Crony source statistics using command:

chronyc sourcestats -v

The sample of output is:

# chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^- ip148.ip-15-204-21.us         2  10   377  1038  -3044us[-3030us] +/-   75ms
^* time.cloudflare.com           3  10   377   993    -99us[  -85us] +/-   10ms
^+ pluto1.plutomail.io           2  10   377   333   -177us[ -177us] +/-   23ms
^- nu.binary.net                 2  10   377   578   +622us[ +622us] +/-   34ms
[root@dallas ~]# chronyc sourcestats -v
                             .- 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
==============================================================================
ip148.ip-15-204-21.us       7   5  103m     -0.260      1.205  -3106us   928us
time.cloudflare.com        14   5  128m     +0.014      0.068    -31us   116us
pluto1.plutomail.io         9   5  137m     -0.011      0.071    +71us    97us
nu.binary.net              11   6  129m     +0.007      0.015   +678us    27us
Congratulations, now we have successfully synchronize our CentOS 9 Stream system time with Chrony.

ServerDiary

ServerDiary

Leave a Reply

Your email address will not be published. Required fields are marked *