What is Chrony: Importance, Benefits, and Installation Tips

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.

What is Chrony

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.

The importance of Chrony

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.

The Difference Between NTP and Chrony

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.

What is Chrony?

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.

Installing NTP with Chrony on Amazon Linux

To install Chrony on Amazon Linux, you can follow the following steps:

  1. Connect to your Amazon Linux server using SSH or any other remote access tool.
  2. Uninstall NTP:
sudo yum erase 'ntp*'
  1. Make sure you have superuser privileges or use the ‘sudo’ command in the following steps to execute the instructions with elevated permissions.
  2. Update the system packages by running the following command:
sudo yum update
  1. Now, you can install Chrony using the Yum package manager:
sudo yum install chrony
  1. Open the /etc/chrony.conf file using a text editor (such as vim or nano).
    sudo nano /etc/chrony.conf
    Make sure the file includes the following line:
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.

  1. After the installation is complete, you can start the Chrony service with the following command:
sudo service chronyd start
  1. To check the status of the service, run the command:
sudo service chronyd status

Chrony will now be up and running on your Amazon Linux server.

  1. Use the chkconfig command to configure chronyd to start on every system boot:
sudo chkconfig chronyd on
  1. Check that chrony is using IP address 169.254.169.123 to synchronize time.
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.

  1. Check the time synchronization metrics reported by chrony.
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

Installing Chrony on Ubuntu

To install NTP with Chrony on Ubuntu, follow these steps:

  1. Connect to your Ubuntu server using SSH or any other remote access tool.
  2. Make sure you have superuser privileges or use the sudo command in the following steps to run the instructions with elevated permissions.
  3. Update system packages by running the following command:
sudo apt update
  1. Now you can install Chrony using the APT package manager:
sudo apt install chrony
  1. After installation is complete, the Chrony service will start automatically. You can check the status of the service with the following command:
sudo systemctl status chrony
  1. After installing Chrony, open the /etc/chrony/chrony.conf configuration file with a text editor:
sudo nano /etc/chrony/chrony.conf
  1. Locate the server configuration section and add the following line before any other server or pool statements already present in the file:
server 169.254.169.123 prefer iburst minpoll 4 maxpoll 4

Save the file and exit the text editor.

  1. Restart the Chrony service to apply the changes:
sudo systemctl restart chrony
  1. Check that chrony is using IP address 169.254.169.123 to synchronize time.
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.

  1. Check the time synchronization metrics reported by chrony.
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.

time synchronization

Note

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.

More

Also check out our post about alerts for divergent times on Linux using Chrony and AWS CloudWatch:

Compartilhe / Share
Fernando Müller Junior
Fernando Müller Junior

I am Fernando Müller, a Tech Lead SRE with 16 years of experience in IT, I currently work at Appmax, a fintech located in Brazil. Passionate about working with Cloud Native architectures and applications, Open Source tools and everything that exists in the SRE world, always looking to develop and learn constantly (Lifelong learning), working on innovative projects!

Articles: 39

Receba as notícias por email / Receive news by email

Insira seu endereço de e-mail abaixo e assine nossa newsletter / Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *