Auto Sync Linux clock

1

How to implement the automatic synchronization of clock (date and time) in Linux?

What is the best mechanism?

Googling, I've found this: http://www.howtogeek.com/tips/how-to-sync-your-linux-server-time-with-network-time-servers-ntp/

But isn't it more simple to do this:

  • sudo crontab -e -u root
  • Add: 00-59/1 * * * * /usr/sbin/ntpdate pool.ntp.org

Pedro Reis

Posted 2015-07-31T13:43:01.593

Reputation: 111

Answers

1

Running the time daemon keeps the clock synchronised by making it slightly faster or slower. The time continues to go forwards.

Using ntpdate forcibly resets the clock every time you call it. So if your system clock is slightly fast, the clock will appear to go backwards slightly sometimes. This may confuse some programs, especially make.

pjc50

Posted 2015-07-31T13:43:01.593

Reputation: 5 786

1

There are several implementations for NTP synchronization, ntpd, chrony and systemd-timesyncd, to name a few. Running ntpdate every minute has a lot of drawbacks, for example:

  • time is not adjusted smoothly, so it can jump backwards and/or forwards
  • there is a lot of load on the NTP server you are querying, so please do not implements this "handycraft solution"

NTP daemons on the other hand

  • will adjust the time smoothly, so time will always advance in a normal manner, but sometimes a bit slower, sometimes a bit faster
  • will allow the kernel to apply a general "skew" to the clock to compensate for inaccuracies in the hardware clock (which are always present)
  • thus they will need need to query the NTP server only very few times per hour or even less

And most of the time, all you will need to do is to install the package. Debian-based systems will usually start the daemon right away, on others you may need to start and enable them.

Stefan Seidel

Posted 2015-07-31T13:43:01.593

Reputation: 8 812

0

You can use systemd-timesyncd.

Stop chrony :

systemctl stop chronyd
systemctl disable chronyd

Or stop ntpd (perhaps ntp) :

systemctl stop ntpd
systemctl disable ntpd

Edit the /etc/systemd/timesyncd.conf file, like this :

[Time]
NTP=0.fr.pool.ntp.org 1.fr.pool.ntp.org 2.fr.pool.ntp.org 3.fr.pool.ntp.org

Enable and run the systemd-timesyncd daemon :

timedatectl set-ntp true

Denis Szalkowski

Posted 2015-07-31T13:43:01.593

Reputation: 1