Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
The world of technology is brimming with essential tools that often go unnoticed by the majority of users. One of these lesser-known tools is the Network Time Protocol (NTP) and its modern successor, Chrony. While time is a fundamental part of our everyday life, many people are unaware of the significance of accurate time synchronization in servers and networks. In this text, we will delve into the realm of NTP and Chrony, unraveling their functionalities, differences, and the contexts in which each is applicable.
NTP is a protocol that has been established for decades, but few are aware of its existence. Its primary function is to synchronize the clocks of computers on a network, enabling all devices to agree on the current time. This might seem trivial at first glance, but accurate time synchronization is crucial for a wide range of applications, from financial transactions to the security of critical systems.
Despite the relevance of NTP, a new alternative, Chrony, has gained prominence recently. Developed as a response to challenges encountered in modern network environments, Chrony offers a more flexible and adaptive approach to time synchronization. Its aim is to deal with network latency variations and ensure the server’s clock is always accurate.
It’s surprising that these tools, so vital for the stability and performance of servers and networks, remain widely unknown. While many users might not have direct contact with NTP or Chrony in their daily activities, it’s important to recognize the significance of these tools behind the scenes of the technology we use.
This post will be part of a series of posts that will introduce a very interesting observability solution for those using Auto Scaling Groups in AWS, involving reliability regarding the timing of servers within the Auto Scaling Group.
Table of Contents
Chrony plays a crucial role in maintaining time accuracy on a server. Accurate time synchronization is essential for a wide range of tasks and processes occurring in a network environment. In this regard, Chrony offers a series of benefits that contribute to the overall stability and performance of a server.
Firstly, Chrony is responsible for providing a reliable time reference for the server. It employs advanced algorithms and precise measurement techniques to calculate the difference between the server’s clock and an external time source, such as an NTP (Network Time Protocol) server. By keeping the time consistently updated, Configuring NTP with Chrony ensures that server operations are executed consistently and in coordination.
Furthermore, Chrony can handle variations in network latency by compensating for delays and estimating the travel time between the server and the time source. This is especially useful in network environments where latency can vary significantly, such as in long-distance networks or networks subject to traffic fluctuations. Chrony’s ability to intelligently adjust time, considering these variations, ensures that the server maintains accurate synchronization even in challenging conditions.
Another important aspect is Chrony’s ability to detect and correct any deviations in the system time. Chrony’s discipline algorithm continually monitors the server’s clock, identifying and correcting minor deviations over time. This is essential to maintain stability and time consistency on the server, avoiding errors and inconsistencies that could negatively impact the performance of applications and services.
In summary, Chrony plays a fundamental role in ensuring time accuracy on a server. By providing a reliable time reference, handling latency variations, and correcting deviations in the system time, it contributes to the stability, performance, and proper coordination of operations in a network environment. Its intelligent adjustment capabilities and continuous improvement make Chrony a valuable choice for time synchronization on servers.
NTP (Network Time Protocol) and Chrony are two widely used protocols for time synchronization in servers. While both share the common goal of providing accurate time, they have distinct characteristics that make them suitable for different contexts and requirements.
NTP is a long-established protocol widely adopted for time synchronization in networks. It’s designed to provide high accuracy in environments where latency is relatively stable and low. NTP employs complex algorithms to calculate the difference between the server’s clock and various external time sources, such as reference servers. It’s particularly useful in networks with reliable connectivity and low latency variation, like local networks or high-quality WANs.
On the other hand, Chrony is a more recent and flexible alternative to NTP. It was developed with a focus on adaptability to network latency variations and the ability to handle challenging environments. Chrony uses advanced techniques to measure network latency and calculate the difference between the server’s clock and an external time source, such as an NTP server. This adaptive approach allows Chrony to synchronize accurately even in networks subject to significant latency fluctuations, like long-distance networks or networks with variable traffic.
In terms of configuration and management, NTP tends to be more complex, requiring fine-tuning to optimize performance. Chrony, on the other hand, is known for its ease of configuration and operation, making it a convenient choice for environments where simplicity is valued.
To install Chrony on Amazon Linux, you can follow the following steps:
sudo yum erase 'ntp*'
sudo yum update
sudo yum install chrony
/etc/chrony.conf
file using a text editor (such as vim or nano).sudo nano /etc/chrony.conf
server 169.254.169.123 prefer iburst minpoll 4 maxpoll 4
If the line is present, the Amazon Time Sync Service is already configured. In that case, proceed to the next step. Otherwise, add the line after any other server or pool statements already present in the file and save your changes.
sudo service chronyd start
sudo service chronyd status
Chrony will now be up and running on your Amazon Linux server.
sudo chkconfig chronyd on
chronyc sources -v
Expected result looks like this:
210 Number of sources = 7
.-- 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
===============================================================================
^* 169.254.169.123 3 6 17 43 -30us[ -226us] +/- 287us
^- ec2-12-34-231-12.eu-west> 2 6 17 43 -388us[ -388us] +/- 11ms
^- tshirt.heanet.ie 1 6 17 44 +178us[ +25us] +/- 1959us
^? tbag.heanet.ie 0 6 0 - +0ns[ +0ns] +/- 0ns
^? bray.walcz.net 0 6 0 - +0ns[ +0ns] +/- 0ns
^? 2a05:d018:c43:e312:ce77:> 0 6 0 - +0ns[ +0ns] +/- 0ns
^? 2a05:d018:dab:2701:b70:b> 0 6 0 - +0ns[ +0ns] +/- 0ns
In the returned output, ^* indicates the preferred time source.
chronyc tracking
Expected output is similar to this:
Reference ID : A9FEA97B (169.254.169.123)
Stratum : 4
Ref time (UTC) : Wed Nov 22 13:18:34 2017
System time : 0.000000626 seconds slow of NTP time
Last offset : +0.002852759 seconds
RMS offset : 0.002852759 seconds
Frequency : 1.187 ppm fast
Residual freq : +0.020 ppm
Skew : 24.388 ppm
Root delay : 0.000504752 seconds
Root dispersion : 0.001112565 seconds
Update interval : 64.4 seconds
Leap status : Normal
To install NTP with Chrony on Ubuntu, follow these steps:
sudo apt update
sudo apt install chrony
sudo systemctl status chrony
sudo nano /etc/chrony/chrony.conf
server 169.254.169.123 prefer iburst minpoll 4 maxpoll 4
Save the file and exit the text editor.
sudo systemctl restart chrony
chronyc sources -v
Expected output:
210 Number of sources = 7
.-- 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
===============================================================================
^* 169.254.169.123 3 6 17 12 +15us[ +57us] +/- 320us
^- tbag.heanet.ie 1 6 17 13 -3488us[-3446us] +/- 1779us
^- ec2-12-34-231-12.eu-west- 2 6 17 13 +893us[ +935us] +/- 7710us
^? 2a05:d018:c43:e312:ce77:6 0 6 0 10y +0ns[ +0ns] +/- 0ns
^? 2a05:d018:d34:9000:d8c6:5 0 6 0 10y +0ns[ +0ns] +/- 0ns
^? tshirt.heanet.ie 0 6 0 10y +0ns[ +0ns] +/- 0ns
^? bray.walcz.net 0 6 0 10y +0ns[ +0ns] +/- 0ns
In the returned output, the line starting with ^* indicates the preferred time source.
chronyc tracking
Output will look like this:
Reference ID : 169.254.169.123 (169.254.169.123)
Stratum : 4
Ref time (UTC) : Wed Nov 29 07:41:57 2017
System time : 0.000000011 seconds slow of NTP time
Last offset : +0.000041659 seconds
RMS offset : 0.000041659 seconds
Frequency : 10.141 ppm slow
Residual freq : +7.557 ppm
Skew : 2.329 ppm
Root delay : 0.000544 seconds
Root dispersion : 0.000631 seconds
Update interval : 2.0 seconds
Leap status : Normal
Chrony will now be up and running on your server.
Keep in mind that the instructions above assume you are using updated versions of Amazon Linux and Ubuntu. If you are using older versions, there may be slight differences in commands and installation procedures.
Also check out our post about alerts for divergent times on Linux using Chrony and AWS CloudWatch: