User Tools

Site Tools


linux:linux_systemd_chrony

Chrony as NTP service

First update the /etc/chrony.conf

[root@fedora22 ~]# cat /etc/chrony.conf 
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
pool 2.fedora.pool.ntp.org iburst

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

# In first three updates step the system clock instead of slew
# if the adjustment is larger than 10 seconds.
makestep 10 3

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

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

# Serve time even if not synchronized to any NTP server.
#local stratum 10

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

# Specify key number for command authentication.
commandkey 1

# Generate new command key on start if missing.
generatecommandkey

# Disable logging of client accesses.
noclientlog

# Send message to syslog when clock adjustment is larger than 0.5 seconds.
logchange 0.5

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

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

If you want to use you linux as NTP server, add the following line (all are required):

local stratum 10
port 123
allow

Enable chrony service:

[root@fedora22 ~]# systemctl enable chronyd
[root@fedora22 ~]# systemctl start chronyd
[root@fedora22 ~]# systemctl status chronyd# systemctl status chronyd
[root@fedora22 ~]# systemctl status chronyd.service 
   chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: active (running) since mer. 2015-08-26 16:49:45 CEST; 51min ago
 Main PID: 809 (chronyd)
   CGroup: /system.slice/chronyd.service
           └─809 /usr/sbin/chronyd -4

août 26 16:49:44 fedora22 systemd[1]: Starting NTP client/server...
août 26 16:49:44 fedora22 chronyd[809]: chronyd version 2.1.1 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +DEBUG +ASYNCDNS +IPV6 +SECHASH)
août 26 16:49:45 fedora22 chronyd[809]: Frequency -2.945 +/- 0.062 ppm read from /var/lib/chrony/drift
août 26 16:49:45 fedora22 systemd[1]: Started NTP client/server.
août 26 16:49:57 fedora22 chronyd[809]: Selected source 46.29.177.18
août 26 16:49:57 fedora22 chronyd[809]: System clock wrong by -0.605560 seconds, adjustment started

Use chronyc to check the status of the service:

[root@fedora22 ~]# chronyc sourcestats
210 Number of sources = 2
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
==============================================================================
46.29.177.18               20  11   32m     +0.016      0.415  +8403ns   277us
sns2.papa-razzi-networks.  17  11   33m     -0.281      0.420  +7687us   213us

[root@fedora22 ~]# chronyc sources
210 Number of sources = 2
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* 46.29.177.18                  2   9   377     6    +31us[  +59us] +/-   30ms
^- sns2.papa-razzi-networks.     2   9   377   261  +7575us[+7597us] +/-  189ms

[root@fedora22 ~]# chronyc tracking
Reference ID    : 46.29.177.18 (46.29.177.18)
Stratum         : 3
Ref time (UTC)  : Wed Aug 26 15:31:59 2015
System time     : 0.000028182 seconds fast of NTP time
Last offset     : +0.000028324 seconds
RMS offset      : 0.003814944 seconds
Frequency       : 2.944 ppm slow
Residual freq   : +0.004 ppm
Skew            : 0.345 ppm
Root delay      : 0.013559 seconds
Root dispersion : 0.018800 seconds
Update interval : 518.4 seconds
Leap status     : Normal

Check a particular NTP server (like ntpdate command)

[root@fedora22 ~]# systemctl stop chronyd
[root@fedora22 ~]#  chronyd -q 'server 10.10.10.1 iburst'
2021-02-12T09:36:28Z chronyd version 3.4 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +SECHASH +IPV6 +DEBUG)
2021-02-12T09:36:28Z Initial frequency -84.650 ppm
2021-02-12T09:36:33Z System clock wrong by 0.003007 seconds (step)
2021-02-12T09:36:33Z chronyd exiting
[root@fedora22 ~]# systemctl start chronyd
linux/linux_systemd_chrony.txt · Last modified: 2021/02/12 10:54 by manu