In this video, we'll talk about managing time services.
On Linux, typically Network Time Protocol, or NTP, is used to pick up time from the internet
and to synchronize the local machine.
The different Linux distributors have different solutions to work with NTP.
It can be the somewhat older NTPD, or SystemD TimeSyncD, which is integrated in SystemD.
And on Red Hat and Family, there's CronyD.
All of these are services that are used to synchronize with time services that have been
defined.
Commonly used time services are in pool.ntp.org.
They are publicly available.
They are very accurate as they are connected to an atomic clock, so many servers are using
this to synchronize.
The TimeDateCTL utility can be used to set time, to synchronize time, as well as to set
time zones.
It's a relatively new utility, and it's offering everything you need to have the accurate time
on your system.
HWClock is another utility.
You use it to manage hardware time and synchronize system time with hardware time.
And that is useful because your system time is always set based on hardware time.
And next, your system time is synchronized with internet time, and if the difference
is too big, then NTP refuses to synchronize.
And that is why it might make sense to set your system time based on the hardware clock
correctly using HWClock.
The Date utility can be used to set local time, but as you can also do that with TimeDateCTL,
date nowadays is considered a little bit legacy.
But date is useful for all the different display formats.
So you can easily use it to show the time in a way that makes sense in your geographical
area.
Another legacy utility is TZSelect, which you can use to select a current time zone.
But nowadays, TimeDateCTL is a modern alternative, and I would recommend using that.
Let's talk about SystemD TimeSyncD.
SystemD TimeSyncD is a SystemD service that provides a simple NTP-based time synchronization.
And if you are using a complex configuration, it is recommended not to use SystemD TimeSyncD.
And that is exactly why on Reddit, you will find ChronyD instead of SystemD TimeSyncD.
The TimeDateCTL is a common utility to work with SystemD TimeSyncD.
And SystemD TimeDateD is a tiny daemon that can be used to control time in related settings.
It can control the start and stop of the SystemD TimeSyncD service.
On Reddit family, you should learn about ChronyD.
ChronyD reads the etcchrony.conf configuration file for instructions on how to synchronize.
And ChronyD is running on every server, because every server needs to be synchronized with
the internet.
If you want to check current synchronization status, you can use ChronyC Sources.
Let me show you.
So first, I want to show you date, which is showing that it's Wednesday, August 13, 850.
Then I'm using TimeDateCTL TabTab, where TabTab is showing all the different commands.
So TimeDateCTL status is giving me current information, a lot more detailed.
So it's giving me the time zone, it's giving information about the system clock, synchronization,
the local time versus universal time.
And it also has commands to set the time zone if you want to.
Now HWclock is the third command that matters.
And HWclock is giving the hardware clock.
And this hardware clock should be pretty close to the system clock.
And if that is not the case, you can use the different options that are available.
As you can see, there's a lot.
There are only two that really matter.
And these are minus S for hardware clock to Sys, and minus W for Sys to HC.
So either your hardware clock is correct and the system clock is not, then you go for minus
S. But more common is that your hardware clock is off because of a battery problem on the
hardware clock, for instance.
Then you set the time on the system and you synchronize it to the hardware clock.
And after that, you will be all right.
Now SystemCTL status on cronyd.service is showing that the cronyd service is currently loaded.
It's also giving nice information about the service that it uses to synchronize with.
Alternatively, you can use cronyc sources, which is giving the main information, but
it is not as readable.
Now what you care about in time synchronization is that you are synchronizing with a server
that has a reliable stratum.
The stratum indicates how close you are to the ultimate source of time.
Stratum 1 means that you're directly on internet time.
Stratum 2 means that you are synchronizing with stratum 1.
Stratum 3 means that you are synchronizing with a stratum 2 and so on.
Typically, stratum 11 is never to be found in internet synchronization because there
will be 10 servers between the stratum 11 and the internet.
But stratum 11 is commonly used for on-site synchronization.
So if you want to offer your own NTP server without being connected to the internet,
stratum 11 should be used.
So that if ever you connect to the internet, internet time, which is more reliable, will
always win.
If ever you see stratum 16, that means that the server in question could not be used.
And a configuration behind crony is in etc.crony.conf.
So there you can see the line pool2.centOS or pool.ntp.org, which is indicating that
it's synchronizing time from there.
And the alternative option is server, followed by an IP address or a server.
And that will make that you synchronize your time with that specific server.
After adding a server, don't forget to use systemctl status on cronyd.
And also don't forget cronyc sources to figure out if synchronization is working all right.