Syncing time in linux

How to Synchronize Time with Chrony NTP in Linux

The Network Time Protocol (NTP) is a protocol used to synchronize computer system clocks automatically over a network. The machine can have the system clock use Coordinated Universal Time (UTC) rather than local time.

Maintaining accurate time on Linux systems, especially servers is an important task for many reasons. For example, in a networked environment, accurate timekeeping is required for accurate timestamps in packets and system logs for root-cause analysis, determining when problems occurred, and finding correlations.

Chrony is now the default NTP implementation package on the latest versions of RHEL-based distributions such as CentOS Stream, Fedora, Rocky Linux & AlmaLinux, and Debian-based distributions such as Ubuntu & Linux Mint, among others, and comes pre-installed by default.

The Chrony package consists of chronyd, a daemon that runs in userspace, and chronyc a command-line program for monitoring and controlling chronyd.

Chrony is a versatile NTP implementation and performs well in a wide range of conditions (check out the comparison of the chrony suite to other NTP implementations). It can be used to synchronize the system clock with NTP servers (act as a client), with a reference clock (e.g a GPS receiver), or with a manual time input. It can also be employed as an NTPv4 (RFC 5905) server or peer to provide a time service to other computers in the network.

In this article, you will learn how to synchronize server time with NTP in Linux using chrony.

Installing Chrony in Linux Server

In most Linux systems, the chrony command is not installed by default. To install it, execute the below command.

$ sudo yum install chrony [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ sudo apt install chrony [On Debian, Ubuntu and Mint]

Install Chrony in Linux

The default location for the chrony daemon is /usr/sbin/chronyd and the command line program will be installed to /usr/bin/chronyc.

Once the installation is complete, start the chrony service and enable it to automatically start at system boot, then check if it is up and running.

# systemctl enable --now chronyd # systemctl status chronyd

Check Chrony Status

To cross-check if chrony is now up and running fine and to see the number of servers and peers that are connected to it, run the following chronyc command.

Читайте также:  Аналоги everest for linux

Check Chrony Activity

Checking Chrony Synchronization in Linux

To display information (list of servers available, status, and offsets from the local clock and the source) about the current time sources that chronyd is accessing, run the following command with the -v flag shows the description for each column.

# chronyc sources OR # chronyc sources -v

Check Chronyd Time Sources

Concerning the previous command, to display other useful information for each of the sources currently being examined by chronyd (such as the drift rate and offset estimation process), use the sourcestats command.

# chronyc sourcestats OR # chronyc sourcestats -v

Check Chronyd Source Stats

To check chrony tracking, run the following command.

In the output of this command, the reference ID specifies the name (or IP address) if available, of the server to which the computer is currently synchronized, out of all the available servers.

Display Chrony Tracking

Configuring Chrony Time Sources in Linux

The main chrony configuration file is located at /etc/chrony.conf (CentOS/RHEL/Fedora) or /etc/chrony/chrony.conf (Ubuntu/Debian).

When installing a Linux OS in the cloud, your system should have some default servers or a pool of servers added during the installation process. To add or change the default servers, open the configuration file for editing:

# vi /etc/chrony.conf OR # vi /etc/chrony/chrony.conf

You can either add several servers using the server directive as shown.

server 0.europe.pool.ntp.org iburst server 1.europe.pool.ntp.org iburst server 2.europe.pool.ntp.org ibusrt server 3.europe.pool.ntp.org ibusrt

Add NTP Servers

or in most cases, it’s best to use ntppool.org to find an NTP server. This allows the system to try to find the closest available servers for you. To add a pool, use the pool directive:

Add a Pool of NTP Servers

There are many other options you can configure in the file. After making changes, restart the chrony service.

$ sudo systemctl restart chrony OR # systemctl restart chronyd

To show information about the current time sources that chronyd is querying, run the following command once more.

View Chronyd Time Sources

To check the chrony tracking status, run the following command.

Check Chrony Synchronizing Status

To display the current time on your system, check whether the system clock is synchronized and whether NTP is indeed active, run the timedatectl command:

Check Current Server Time

That brings us to the end of this guide. If you have any questions, reach us via the comment section below. For more information, check out: using the chrony suite to configure NTP from the RHEL documentation or using chrony to configure NTP from the Ubuntu official blog.

Читайте также:  Linux отключить сетевой интерфейс

Источник

Commands to Sync Time with NTP Server in Linux

For many people, computer clocks in your devices, network machines, and servers are generally accurate. But that’s not true! These clocks are manually maintained and backed by batteries which over time drift the clock, especially in the older machines.

So why is accurate time so important? Having exact time on your machine is quite significant because of several reasons. Many aspects of your computer activity are linked with time. Perfectly synched time is crucial for tracking security-related issues; troubleshooting can become quite difficult if the timestamps in log files are incorrect. Even for financial services, keeping accurate time is critical.

Many companies solve time-related issues by connecting their networks with NTP. So what is NTP? Let’s dig into it first:

What is NTP

The full form of NTP is “Network Time Protocol”, which has been one of the most authentic ways to synchronize the clock over a network. If your system uses NTP, you don’t need to check and set your time manually. It automatically updates the clock every time the device reboots. It is an extremely accurate way to update the clock of your device. Since the internet is everywhere, NTP is being used by every modern computer.

How to Enable NTP Synchronization on Linux

Most of the Linux distributions are using “systemd”, which comes with NTP for clock synchronization. To verify this, use the command given below:

It indicates that NTP is active. If, for some reasons, it is not active, then use the below-mentioned command to enable it:

How to Enable NTP for Linux Distributions without “systemd”

But what if your distribution does not come with “systemd”? Well, in that case, you can install NTP.

Источник

About time synchronisation

Network Time Protocol (NTP) is a networking protocol for synchronising time over a network. Basically, a client requests the current time from a server, and uses it to set its own clock.

Behind this simple description, there is a lot of complexity. There are three tiers of NTP servers; tier one NTP servers are connected to atomic clocks, while tier two and tier three three servers spread the load of actually handling requests across the Internet.

Читайте также:  Линукс минт последний релиз

The client software is also a lot more complex than you might expect. It must factor in communication delays and adjust the time in a way that does not upset all the other processes that run on the server. Luckily, all that complexity is hidden from you!

By default, Ubuntu uses timedatectl / timesyncd to synchronise time, and they are available by default. See our guide If you would like to know how to configure timedatectl and timesyncd .

Users can also optionally use chrony to serve NTP.

How time synchronisation works

Since Ubuntu 16.04, timedatectl / timesyncd (which are part of systemd ) replace most of ntpdate / ntp .

About timesyncd

timesyncd replaces not only ntpdate , but also the client portion of chrony (formerly ntpd ). So, on top of the one-shot action that ntpdate provided on boot and network activation, timesyncd now regularly checks and keeps your local time in sync. It also stores time updates locally, so that after reboots the time monotonically advances (if applicable).

About timedatectl

If chrony is installed, timedatectl steps back to let chrony handle timekeeping. This ensures that no two time-syncing services can conflict with each other.

ntpdate is now considered deprecated in favor of timedatectl (or chrony ) and is no longer installed by default. timesyncd will generally keep your time in sync, and chrony will help with more complex cases. But if you had one of a few known special ntpdate use cases, consider the following:

  • If you require a one-shot sync, use: chronyd -q
  • If you require a one-shot time check (without setting the time), use: chronyd -Q

While use of ntpd is no longer recommended, this also still applies to ntpd being installed to retain any previous behaviour/config that you had through an upgrade. However, it also implies that on an upgrade from a former release, ntp / ntpdate might still be installed and therefore renders the new systemd -based services disabled.

Further reading

  • ntp.org: home of the Network Time Protocol project
  • pool.ntp.org: project of virtual cluster of timeservers
  • Freedesktop.org info on timedatectl
  • Freedesktop.org info on systemd-timesyncd service
  • Chrony FAQ
  • Feeding chrony from GPSD
  • Also see the Ubuntu Time wiki page for more information.

Источник

Оцените статью
Adblock
detector