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.
Time design
Sometime an ugly but a relevant picture is better than a lot of explanations.
What is the reference clock?
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.
What is a stratum?
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).
NTP terminology
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.
Managing NTP
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 ntpd
daemon.
First, download the ntp packages.
$ aptitude install -y ntp ntpdate |
Check your system date:
$ date |
Also check your current timezone:
$ cat timezone |
You can easily change it like this:
$ dpkg-reconfigure tzdata |
Drift away!
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 ntpdate
that 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:
$ date |
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:
$ ntpdate-debian |
Basicly this command will ntpdate
the Debian ntp server.
Tools
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!
$ ntptrace |
Another way to walk throught the stratums layer using ntpq
:
$ ntpq -p |
Hope it will help!
Comments