System clock synchronized: no

Mahdi Mallaki
3 min readJun 11, 2023

--

An easy solution for an unsynchronized clock on Linux

timedatectl command output

Introduction

If your system clock is not synchronized, it can cause several issues. One issue I encountered was that my system logs were displaying an incorrect timestamp. To resolve this, I needed to synchronize the server time with a time server. You can achieve this by installing various clock synchronization tools on Linux, such as ntpd. However, there are better alternatives available, such as chrony. In this article, I will use the chrony tool to synchronize the VM clock because it is simple and easy to set up compared to competitors like ntpd.

Chronyd VS Ntpd

Chronyd and Ntpd are both used to control the computer’s clock, but they differ in their algorithms. Chronyd can work well even with intermittent external time references, perform well during network congestion, synchronize the clock faster and with better accuracy, adapt quickly to sudden changes in clock rate, and adjust the clock rate on Linux systems with broken or unstable clocks. Additionally, Chronyd can support isolated networks and estimate the rate of gain or loss of the real-time clock.

1- Installation of Chrony

first, you need to install chrony with the following command:

# debian or ubuntu
$ sudo apt install chrony -y
# RHEL family
$ sudo yum install chrony -y

2- Configuration of Chrony

the configuration is so simple and you can find its configuration file at /etc/chrony.conf location. you just need to change the target server (It is already configured to connect to a public time server on the internet, but you have the flexibility to change it if needed):

pool 192.168.1.5 iburst

3- Maintenance of Chrony

somewhile after you installed the Chrony, you may see something like this:

A sample of a failed chronyd systemd service

the chronyd service stopped and did not start automatically! it’s so bad and you have to start it manually every time it crashes. but I have a trick to start it automatically when the service went down. you can put the Restart=Always inside the service file to start automatically after crashing.

edit the file /usr/lib/systemd/system/chronid.service and put Restart=always it inside the [Service] section. it should be something like this:

systemd configuration of chronyd service

then you need to restart the chronyd service:

systemctl daemon-reload
systemctl restart chronyd

Feedback

If you have any feedback or suggestions for improving my code, please leave a comment on this post or send me an email at mallakimahdi@gmail.com. I would greatly appreciate your contributions to help make this article better. If you enjoyed this post, be sure to follow me to stay updated on my latest articles.

--

--

No responses yet