Working with time
I’m late, I’m late, For a very important date. No time to say “Hello, Goodbye”. I’m late, I’m late, I’m late, I’m late! When you setup a new environment, it’s critical to setup the right and the same time on each servers.
Sometime an ugly but a relevant picture is better than a lot of explanations.
This one provides the most accurate time, the universal time. It’s a sort of an atomic clock. In NTP langage, it’s refer to the stratum 0.
Basically, it’s the distance between your current ntp server and the reference clock. By ‘distance’ understand number of servers. The closest server from the reference clock is called the stratum 1. Usually it is connected to the reference clock through a special link. Not a network link, some other dedicated and more accurate connection (serial connection or GPS connection for instance).
Here some commons NTP terms:
Jitter, it’s measurement of the variance in latency on the network.
Drift, it’s when the local clock becomes less accurate. The ntp daemon can take care of this variation.
There is 2 way to manage ntp. First you can use the
ntpd daemon, it’s continuous and re-adjust small differences. But it won’t work if the time difference is too important. The second consists in using the
ntpdate command. It acts as a ‘one shot time’ adjustment and takes effect immediatly. The only thing you have to be aware of is they can’t work in the same time. It makes sense since they will use the same port. For instance, using the
ntpdate command while the
ntpd daemon is running will result by an error. Of course, the
ntpd is already listenning on port 123. Before using the
ntpdate command, stop the
First, download the ntp packages.
$ aptitude install -y ntp ntpdate
Check your system date:
Also check your current timezone:
$ cat timezone
You can easily change it like this:
$ dpkg-reconfigure tzdata
Sometimes the time difference between your internal clock and the ntp server is too important. The ntpd daemon won’t even try to correct it. Clocks have to be nearly in sync before starting
ntpd. Of course this doesn’t apply to
ntpdatethat will always set the clock according to the server reference, not matter of the time difference.
You can try to setup manually the date like this:
$ date 09011840
Wait a few seconds and see if the ntp daemon readjusted the time properly.
If it’s not efficient stop the ntpd daemon:
$ service ntp stop
Let’s say your current time is:
But it is currently
Sunday Apr 15 01:15.
Usually you will use the
ntpdate command like below:
$ ntpdate -s pool.ntp.org
On Debian, I recently discover this usefull command:
Basicly this command will
ntpdate the Debian ntp server.
As a traceroute will do it, you can know your current position (your stratum) from the reference clock. The
ntptrace will help you, just trace it!
Another way to walk throught the stratums layer using
$ ntpq -p
Hope it will help!