U1.37 Ubuntu Quick Start (QS): Time synchronization (chrony) - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki

Reading

Starting with

  • Pre-installed DHCP in the virtual environment (for example, a hardware implementation of a DHCP server in a modem)
  • Deploy four Ubuntu 20.04 TLS virtual machines. Consult the articles U1.01 and U1.02
    • Device name = u2004m01, ip = 192.168.100.15
    • Device name = u2004m02, ip = 192.168.100.16
    • Device name = u2004m03, ip = 192.168.100.18

Installation (u2004m01, u2004m02, u2004m03)

  • run the command
sudo apt install chrony -y
Click to show the responce
Setting up chrony (3.5-6ubuntu6.2) ...
Creating '_chrony' system user/group for the chronyd daemon…

Creating config file /etc/chrony/chrony.conf with new version

Creating config file /etc/chrony/chrony.keys with new version
Created symlink /etc/systemd/system/chronyd.service → /lib/systemd/system/chrony.service.
Created symlink /etc/systemd/system/multi-user.target.wants/chrony.service → /lib/systemd/system/chrony.service.

Config file: /etc/chrony/chrony.conf

Status

systemctl status chronyd

Enable chrony daemon upon boot

sudo systemctl enable chronyd

Tracking

chronyc tracking

Sources

chronyc sources
Click to show the responce
yury@u2004m02:~$ chronyc sources -v
210 Number of sources = 7
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^+ golem.canonical.com           2   6   377    58  -1612us[-1589us] +/-   55ms
^+ alphyn.canonical.com          2   6   377    56  +1154us[+1154us] +/-  122ms
^+ pugot.canonical.com           2   6   377    57  +3564us[+3587us] +/-   50ms
^+ chilipepper.canonical.com     2   6   377   122  -3404us[-3625us] +/-   66ms
^* 194.158.196.171               2   6   377    57  -1728us[-1705us] +/-   46ms
^? gate.mgts.by                  0   8     0     -     +0ns[   +0ns] +/-    0ns
^? mirror.datacenter.by          0   8     0     -     +0ns[   +0ns] +/-    0ns

sourcestats

chronyc sourcestats -v

ntpdata

sudo chronyc ntpdata

Stop and Start

sudo systemctl stop chrony
sudo systemctl start chrony

Making an NTP server

Allow NTP Service in firewall

sudo firewall-cmd --add-service=ntp –permanent
sudo firewall-cmd --reload

u2004m01 as NTP server

sudo nano /etc/chrony/chrony.conf
  • add two lines to the end of chrony.conf file
local stratum 10
allow 192.168.100.0/24
Click to show the chrony.conf
# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usuable directives.

# This will use (up to):
# - 4 sources from ntp.ubuntu.com which some are ipv6 enabled
# - 2 sources from 2.ubuntu.pool.ntp.org which is ipv6 enabled as well
# - 1 source from [01].ubuntu.pool.ntp.org each (ipv4 only atm)
# This means by default, up to 6 dual-stack and up to 2 additional IPv4-only
# sources will be used.
# At the same time it retains some protection against one of the entries being
# down (compare to just using one of the lines). See (LP: #1754358) for the
# discussion.
#
# About using servers from the NTP Pool Project in general see (LP: #104525).
# Approved by Ubuntu Technical Board on 2011-02-08.
# See http://www.pool.ntp.org/join.html for more information.
pool ntp.ubuntu.com        iburst maxsources 4
pool 0.ubuntu.pool.ntp.org iburst maxsources 1
pool 1.ubuntu.pool.ntp.org iburst maxsources 1
pool 2.ubuntu.pool.ntp.org iburst maxsources 2

# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /etc/chrony/chrony.keys

# This directive specify the file into which chronyd will store the rate
# information.
driftfile /var/lib/chrony/chrony.drift

# Uncomment the following line to turn logging on.
#log tracking measurements statistics

# Log files location.
logdir /var/log/chrony

# Stop bad estimates upsetting machine clock.
maxupdateskew 100.0

# This directive enables kernel synchronisation (every 11 minutes) of the
# real-time clock. Note that it can’t be used along with the 'rtcfile' directive.
rtcsync

# Step the system clock instead of slewing it if the adjustment is larger than
# one second, but only in the first three clock updates.
makestep 1 3

# Making NTP server
local stratum 10
allow 192.168.100.0/24
  • Note: The line “local stratum 10″ makes Linux Server as chrony NTP server and continue to work normally even if it is disconnected from network.
sudo systemctl restart chronyd

sync chrony to local clock for u2004m01

  • modify the config with sudo nano /etc/chrony/chrony.conf
    • add
server 127.127.1.0
allow 127.0.0.0/8
local stratum 10
Click to show chrony.conf
# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usuable directives.

# This will use (up to):
# - 4 sources from ntp.ubuntu.com which some are ipv6 enabled
# - 2 sources from 2.ubuntu.pool.ntp.org which is ipv6 enabled as well
# - 1 source from [01].ubuntu.pool.ntp.org each (ipv4 only atm)
# This means by default, up to 6 dual-stack and up to 2 additional IPv4-only
# sources will be used.
# At the same time it retains some protection against one of the entries being
# down (compare to just using one of the lines). See (LP: #1754358) for the
# discussion.
#
# About using servers from the NTP Pool Project in general see (LP: #104525).
# Approved by Ubuntu Technical Board on 2011-02-08.
# See http://www.pool.ntp.org/join.html for more information.
# pool ntp.ubuntu.com        iburst maxsources 4
# pool 0.ubuntu.pool.ntp.org iburst maxsources 1
# pool 1.ubuntu.pool.ntp.org iburst maxsources 1
# pool 2.ubuntu.pool.ntp.org iburst maxsources 2
server 127.127.1.0

# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /etc/chrony/chrony.keys

# This directive specify the file into which chronyd will store the rate
# information.
driftfile /var/lib/chrony/chrony.drift

# Uncomment the following line to turn logging on.
#log tracking measurements statistics

# Log files location.
logdir /var/log/chrony

# Stop bad estimates upsetting machine clock.
maxupdateskew 100.0

# This directive enables kernel synchronisation (every 11 minutes) of the
# real-time clock. Note that it can’t be used along with the 'rtcfile' directive.
rtcsync

# Step the system clock instead of slewing it if the adjustment is larger than
# one second, but only in the first three clock updates.
makestep 1 3

# Making NTP server
local stratum 10
allow 192.168.100.0/24
allow 127.0.0.0/8
  • restart the service
sudo systemctl restart chronyd
chronyc sources -v
Click to show the responce
yury@u2004m01:~$ chronyc sources -v
210 Number of sources = 1

  .-- 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
===============================================================================
^* localhost                    10   6     7    59    +17ns[+3473ns] +/- 5343ns

make u2004m02 and u2004m02 to be a client of u2004m01

  • with sudo nano /etc/chrony/chrony.conf
    • modify /etc/chrony/chrony.conf
      • comment all pool
      • add
server 192.168.100.15
  • save the file
Click to show the responce
# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usuable directives.

# This will use (up to):
# - 4 sources from ntp.ubuntu.com which some are ipv6 enabled
# - 2 sources from 2.ubuntu.pool.ntp.org which is ipv6 enabled as well
# - 1 source from [01].ubuntu.pool.ntp.org each (ipv4 only atm)
# This means by default, up to 6 dual-stack and up to 2 additional IPv4-only
# sources will be used.
# At the same time it retains some protection against one of the entries being
# down (compare to just using one of the lines). See (LP: #1754358) for the
# discussion.
#
# About using servers from the NTP Pool Project in general see (LP: #104525).
# Approved by Ubuntu Technical Board on 2011-02-08.
# See http://www.pool.ntp.org/join.html for more information.

# pool ntp.ubuntu.com        iburst maxsources 4
# pool 0.ubuntu.pool.ntp.org iburst maxsources 1
# pool 1.ubuntu.pool.ntp.org iburst maxsources 1
# pool 2.ubuntu.pool.ntp.org iburst maxsources 2
server 192.168.100.15

# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /etc/chrony/chrony.keys

# This directive specify the file into which chronyd will store the rate
# information.
driftfile /var/lib/chrony/chrony.drift

# Uncomment the following line to turn logging on.
#log tracking measurements statistics

# Log files location.
logdir /var/log/chrony

# Stop bad estimates upsetting machine clock.
maxupdateskew 100.0

# This directive enables kernel synchronisation (every 11 minutes) of the
# real-time clock. Note that it can’t be used along with the 'rtcfile' directive.
rtcsync

# Step the system clock instead of slewing it if the adjustment is larger than
# one second, but only in the first three clock updates.
makestep 1 3

  • run the commands
sudo systemctl restart chronyd
chronyc sources -v

Click to show the responce
yury@u2004m02:~$ chronyc sources -v
210 Number of sources = 1

  .-- 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
===============================================================================
^? 192.168.100.15                3   6     1    43   +535us[ +535us] +/-   59ms
  • having: ^? 192.168.100.15
  • wait 5 minutes
  • run the commands again
chronyc sources -v
Click to show the responce
yury@u2004m02:~$ chronyc sources -v
210 Number of sources = 1

  .-- 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
===============================================================================
^* 192.168.100.15                3   6   377    42   +281us[ +319us] +/-   51ms
  • having: ^* 192.168.100.15
⚠️ **GitHub.com Fallback** ⚠️