keeping your server’s clock up-to-date

Problem with computers is that day after day, they depart from real time.

Today I checked the hour on my server and it returned “Thu Apr 15 17:25:40 CEST 2010” when in fact it was “Thu Apr 15 17:16:35 CEST 2010”, that is it suffered from close to a -10-minute lag!

This is not good because when apache, db or other third party application is logging data, it’s not logging it on appropriate time. Moreover if later on you synchronize your time and by doing so “go back in time” then old entries becomes new entries and your really new entries are ignored in a blog posting system for instance.

Well that being said, it’s important to keep your server clock synchronized.

How to have your clock synchronized?

Our approach will be to use ‘crontab’ tool and to make it execute a small script every week (if you need to execute it more often, adapt it) using ntpdate.

  1. ensure ntpdate package is set up: “sudo apt-get install ntpdate
  2. edit your crontab (running “sudo crontab -e“) and enter the following line:
    0 0 0 * * ntpdate

    hint: ‘replace ‘0 0 0 * *’ with ‘@weekly’ if you find it more explicit, or with ‘@daily’ if you prefer daily synchronization

  3. save your modification

That’s it.
Every week your system clock will be synchronized with server.



Post a Comment

Your email is never published nor shared. You're allow to say what you want...