39 Time synchronization with NTP #
The NTP (network time protocol) mechanism is a protocol for synchronizing the system time over the network. First, a machine can obtain the time from a server that is a reliable time source. Second, a machine can itself act as a time source for other computers in the network. The goal is twofold—maintaining the absolute time and synchronizing the system time of all machines within a network.
Maintaining an exact system time is important in many situations. The built-in hardware clock does often not meet the requirements of applications such as databases or clusters. Manual correction of the system time would lead to severe problems because, for example, a backward leap can cause malfunction of critical applications. Within a network, it is usually necessary to synchronize the system time of all machines, but manual time adjustment is a bad approach. NTP provides a mechanism to solve these problems. The NTP service continuously adjusts the system time with reliable time servers in the network. It further enables the management of local reference clocks, such as radio-controlled clocks.
Since SUSE Linux Enterprise Desktop 15, chrony
is the default implementation of NTP.
chrony
includes two parts; chronyd
is a daemon that can be started at boot
time and chronyc
is a command line interface program to monitor the
performance of chronyd
, and to change operating parameters at runtime.
Starting with SUSE Linux Enterprise Desktop 15.2, the YaST module for NTP client
configuration configures the systemd-timer instead of the cron daemon
to execute chrony
, when it is not configured to run as a daemon.
To enable time synchronization via active directory, follow the instructions found at Procedure 7.2, “Joining an Active Directory domain using . ”
39.1 Configuring an NTP client with YaST #
The NTP daemon (chronyd
) coming with the chrony
package is preset to use the local computer hardware clock as a time
reference. The precision of the hardware clock heavily depends on its time
source. For example, an atomic clock or GPS receiver is a precise time
source, while a common RTC chip is not a reliable time source. YaST
simplifies the configuration of an NTP client.
In the YaST NTP client configuration (
› ) window, you can specify when to start the NTP daemon, the type of the configuration source, and add custom time servers.39.1.1 NTP daemon start #
You can choose from three options for when to start the NTP daemon:
Select
to manually start thechrony
daemon.Select
to set the system time periodically without a permanently runningchrony
. You can set the .Select
to startchronyd
automatically when the system is booted. This setting is recommended.
39.1.2 Type of the configuration source #
In the
drop-down box, select either or . Set if your server uses only a fixed set of (public) NTP servers, while is better if your internal network offers NTP servers via DHCP.39.1.3 Configure time servers #
Time servers for the client to query are listed in the lower part of the
window. Modify this list as needed with , , and .Click
to add a new time server:In the
field, type the URL of the time server or pool of time servers with which you want to synchronize the machine time. After the URL is complete, click to verify that it points to a valid time source.Activate
to speed up the time synchronization by sending more requests at thechronyd
daemon start.Activate
to speed up the boot time on systems that start thechronyd
daemon automatically and may not have an Internet connection at boot time. This option is useful, for example, for laptops with network connections managed by NetworkManager.Confirm with
.
39.2 Manually configuring NTP in the network #
chrony
reads its configuration from the
/etc/chrony.conf
file. To keep the computer clock
synchronized, you need to tell chrony
what time servers to use. You can
use specific server names or IP addresses, for example:
0.suse.pool.ntp.org 1.suse.pool.ntp.org 2.suse.pool.ntp.org 3.suse.pool.ntp.org
You can also specify a pool name. Pool name resolves to several IP addresses:
pool pool.ntp.org
To synchronize time on multiple computers on the same network, we do not
recommend to synchronize them all with an external server. A good practice
is to make one computer the time server which is synchronized with an
external time server, and the other computers act as its clients. Add a
local
directive to the server's
/etc/chrony.conf
to distinguish it from an
authoritative time server:
local stratum 10
To start chrony
, run:
systemctl start chronyd.service
After initializing chronyd
, it takes a while before the time is
stabilized and the drift file for correcting the local computer clock is
created. With the drift file, the systematic error of the hardware clock can
be computed when the computer is powered on. The correction is used
immediately, resulting in a higher stability of the system time.
To enable the service so that chrony
starts automatically at boot time,
run:
systemctl enable chronyd.service
yast-timesync.service
service
Besides the chronyd.service
service, SLED includes yast-timesync.service
. yast-timesync.service
is triggered by a timer
every 5 minutes and runs chronyd
with the -q
option to
set the system time and exit. Because only one instance of chronyd
can be
running at any given time, do not enable or start both chronyd
-related
services at the same time.
39.3 Configure chronyd
at runtime using chronyc
#
You can use chronyc
to change the behavior of chronyd
at runtime. It
also generates status reports about the operation of chronyd
.
You can run chronyc
either in interactive or non-interactive mode. To
run chronyc
interactively, enter chronyc
on the command line. It
displays a prompt and waits for your command input. For example, to check
how many NTP sources are online or offline, run:
#
chronyc
chronyc> activity 200 OK 4 sources online 2 sources offline 1 sources doing burst (return to online) 1 sources doing burst (return to offline) 0 sources with unknown address
To exit chronyc
's prompt, enter quit
or
exit
.
If you do not need to use the interactive prompt, enter the command directly:
#
chronyc
activity
Changes made using chronyc
are not permanent. They will be lost after the
next chronyd
restart. For permanent changes, modify
/etc/chrony.conf
.
For a complete list of chronyc
commands, see its man page (man
1 chronyc
).
39.4 Dynamic time synchronization at runtime #
Although chronyd
starts up normally on a system that boots without a network
connection, the tool cannot resolve the DNS names of the time servers
specified in the configuration file.
chronyd
keeps trying to resolve the time server names specified by the
server
, pool
, and peer
directives in an increasing time interval until it succeeds.
If the time server will not be reachable when chronyd
is started, you can
specify the offline
option:
server server_address offline
chronyd
will then not try to poll the server until it is enabled using the
following command:
#
chronyc online server_address
When the auto_offline
option is set, chronyd
assumes that
the time server has gone offline when two requests have been sent to it
without receiving a response. This option avoids the need to run the
offline
command from chronyc
when disconnecting the
network link.
39.5 Setting up a local reference clock #
The software package chrony
relies on other programs (such as
gpsd
) to access the timing data via the SHM or SOCK
driver. Use the refclock
directive in
/etc/chrony.conf
to specify a hardware reference clock
to be used as a time source. It has two mandatory parameters: a driver name
and a driver-specific parameter. The two parameters are followed by zero or
more refclock
options. chronyd
includes the following
drivers:
PPS - driver for the kernel
pulse per second
API. For example:refclock PPS /dev/pps0 lock NMEA refid GPS
SHM - NTP shared memory driver. For example:
refclock SHM 0 poll 3 refid GPS1 refclock SHM 1:perm=0644 refid GPS2
SOCK - Unix domain socket driver. For example:
refclock SOCK /var/run/chrony.ttyS0.sock
PHC - PTP hardware clock driver. For example:
refclock PHC /dev/ptp0 poll 0 dpoll -2 offset -37 refclock PHC /dev/ptp1:nocrossts poll 3 pps
For more information on individual drivers' options, see man 8
chrony.conf
.
39.6 Clock synchronization to an external time reference (ETR) #
Support for clock synchronization to an external time reference (ETR) is available. The external time reference sends an oscillator signal and a synchronization signal every 2**20 (2 to the power of 20) microseconds to keep TOD clocks of all connected servers synchronized.
For availability two ETR units can be connected to a machine. If the clock deviates for more than the sync-check tolerance all CPUs get a machine check that indicates that the clock is not synchronized. If this happens, all DASD I/O to XRC enabled devices is stopped until the clock is synchronized again.
The ETR support is activated via two sysfs
attributes;
run the following commands as root
:
echo 1 > /sys/devices/system/etr/etr0/online echo 1 > /sys/devices/system/etr/etr1/online