Table of contents of the article:
Introduction
Time synchronization is a crucial aspect of any computer system. An out-of-sync system clock can cause a variety of problems, ranging from erroneous logs to application and service failures. In the past, ntpdate
was a popular tool used to synchronize the system clock with a Network Time Protocol (NTP) server. However, since the release of RHEL 8 and derivatives, Red Hat has eliminated it ntpdate
and replaced it with Chronyd
. In this post, we will explore what it is ntpdate
, as Chronyd
replaced it and how to use Chronyd
on CentOS 8 and RHEL 8 or derivatives including AlmaLinux, Rocky Linux and similar.
What is ntpdate?
ntpdate
is a software utility that is part of the Network Time Protocol (NTP) suite of protocols and tools. This command is specifically designed to synchronize a computer's system clock with a remote NTP server. The main goal of ntpdate
is to provide a quick and relatively simple mechanism for bringing the system clock into alignment with a reliable time reference. This is especially useful in scenarios where “one-time” time synchronization is needed, such as during system startup or in environments where the machine is not running 24/7.
The functionality of ntpdate
it is focused on immediate time synchronization operations and is not designed to provide real-time or continuous time synchronization. In other words, once the command is run ntpdate
, the system clock is synchronized only once and there are no built-in mechanisms to maintain this synchronization over time. This is one reason why ntpdate
it is often used in combination with ntpd
(Network Time Protocol Daemon) or other NTP daemons.
Ntpd
, Unlike ntpdate
, is a daemon that performs time synchronization in the background, constantly monitoring multiple NTP servers and using sophisticated algorithms to determine the most accurate time. System administrators who need more robust and continuous time synchronization often opt to use ntpd
or other similar services, reserving ntpdate
for initial sync operations or for specific use cases where a one-time sync is sufficient.
Why Chronyd?
With the introduction of RHEL 8 and derivatives, ntpdate
has been deprecated and replaced by Chronyd
, a more modern and flexible daemon for time synchronization. Chronyd
it was designed to work as both a client and a server, providing more accurate and reliable time synchronization than ntpdate
. Furthermore, Chronyd
it is best suited for systems that have intermittent Internet connections or frequently switch between different networks.
Installing Chronyd on CentOS 8 and RHEL 8
To install Chronyd
on CentOS 8 or RHEL 8, follow the steps below:
- Open the terminal: Log in as root user or use
sudo
for subsequent commands. - Update the system: Execute the command
sudo dnf update
to ensure you have all the latest updates. - Install Chronyd: Execute the command
sudo dnf install chrony
. - Enable and start the service: Use the following commands to enable and start the service
chronyd
.sudo systemctl enable chronyd
sudo systemctl start chronyd - Check the status: To make sure that
Chronyd
is running, runsudo systemctl status chronyd
.
Chronyd Advanced Usage Syntax
Once you've completed installing Chronyd on your CentOS 8 or RHEL 8 system, you'll have a variety of commands and options to configure, manage, and monitor time synchronization. These commands are accessible through the command line interface chronyc
, which is the command client for the daemon chronyd
. Below, we delve into some of the most common and useful commands you can use to interact with Chronyd.
View Sync Status Information
The command chronyc tracking
It is extremely useful for getting a detailed picture of the current state of time synchronization. This command provides information such as time offset, network delay, and the last NTP server the system was synchronized with. It's a great starting point for diagnosing problems or getting a general idea of the effectiveness of your NTP setup.
List NTP Servers
To get a complete view of the NTP servers that your system is currently connected to or is trying to connect to, you can use the command chronyc sources
. This command lists all configured NTP servers, also showing the status of each of them, which can be useful for identifying connectivity or latency problems.
Add an NTP Server
If you want to add a new NTP server to your configuration, you will need to edit the configuration file chrony.conf
. This file is generally located in the directory /etc/chrony/
. To add a new server, open the file with a text editor like vi
o nano
and add the following line:
server [server_name] iburst
Here, [nome_server]
is the IP address or domain name of the NTP server you want to add. The option iburst
is recommended because it attempts to quickly synchronize with the server by executing a sequence of queries in rapid succession.
Forcing an Instant Sync
In certain scenarios, such as after making significant changes to the server configuration or network, or in situations where it is critical that the system is accurately aligned to an NTP server, the need to force a time synchronization immediately may arise . In these cases, wait for the demon chronyd
completing its background sync routine may not be a viable option.
To solve this problem and force immediate synchronization, the command chronyc makestep
it is the ideal solution. When executed, this command routes chronyd
to update the system clock as quickly as possible. This is done without taking into account drift settings (the variation of the system clock over time) or time correction limits that might normally affect how fast or how often chronyd
updates the system clock.
It is important to note that the use of the command chronyc makestep
it is a rather drastic action and should be used with caution. It is recommended to use it only when it is absolutely necessary to force an immediate synchronization and not as a common practice. This is because frequently forcing time synchronization could have implications for system stability and the accuracy of logging and other functions that depend on an accurate system clock.
Conclusion
Time synchronization is a vital element for the proper functioning of any system. Although ntpdate
was a useful tool for time synchronization, its deprecation in favor of Chronyd
on RHEL 8 and derivatives represents a significant step forward. Chronyd
offers greater flexibility, accuracy and reliability, making it an excellent choice for time management on modern systems.
By following the installation and setup instructions provided in this post, you should be able to get set up Chronyd
on CentOS 8 and RHEL 8 or derivatives with ease. With Chronyd
, you not only ensure that your system is always synced with the exact time, but you also get more granular control over the syncing process.