1
00:00:00,000 --> 00:00:10,680
In this video, we'll talk about managing time services.

2
00:00:10,680 --> 00:00:16,240
On Linux, typically Network Time Protocol, or NTP, is used to pick up time from the internet

3
00:00:16,240 --> 00:00:19,280
and to synchronize the local machine.

4
00:00:19,280 --> 00:00:24,440
The different Linux distributors have different solutions to work with NTP.

5
00:00:24,440 --> 00:00:30,600
It can be the somewhat older NTPD, or SystemD TimeSyncD, which is integrated in SystemD.

6
00:00:30,600 --> 00:00:33,360
And on Red Hat and Family, there's CronyD.

7
00:00:33,360 --> 00:00:37,439
All of these are services that are used to synchronize with time services that have been

8
00:00:37,439 --> 00:00:39,759
defined.

9
00:00:39,759 --> 00:00:43,000
Commonly used time services are in pool.ntp.org.

10
00:00:43,000 --> 00:00:44,599
They are publicly available.

11
00:00:44,599 --> 00:00:49,240
They are very accurate as they are connected to an atomic clock, so many servers are using

12
00:00:49,240 --> 00:00:51,240
this to synchronize.

13
00:00:51,240 --> 00:00:56,680
The TimeDateCTL utility can be used to set time, to synchronize time, as well as to set

14
00:00:56,680 --> 00:00:57,680
time zones.

15
00:00:57,680 --> 00:01:02,840
It's a relatively new utility, and it's offering everything you need to have the accurate time

16
00:01:02,840 --> 00:01:04,440
on your system.

17
00:01:04,440 --> 00:01:07,320
HWClock is another utility.

18
00:01:07,320 --> 00:01:12,239
You use it to manage hardware time and synchronize system time with hardware time.

19
00:01:12,239 --> 00:01:17,800
And that is useful because your system time is always set based on hardware time.

20
00:01:17,800 --> 00:01:21,120
And next, your system time is synchronized with internet time, and if the difference

21
00:01:21,120 --> 00:01:24,959
is too big, then NTP refuses to synchronize.

22
00:01:24,959 --> 00:01:31,639
And that is why it might make sense to set your system time based on the hardware clock

23
00:01:31,639 --> 00:01:34,720
correctly using HWClock.

24
00:01:34,720 --> 00:01:40,320
The Date utility can be used to set local time, but as you can also do that with TimeDateCTL,

25
00:01:40,320 --> 00:01:43,919
date nowadays is considered a little bit legacy.

26
00:01:43,919 --> 00:01:47,360
But date is useful for all the different display formats.

27
00:01:47,360 --> 00:01:52,720
So you can easily use it to show the time in a way that makes sense in your geographical

28
00:01:52,720 --> 00:01:53,720
area.

29
00:01:53,720 --> 00:02:00,239
Another legacy utility is TZSelect, which you can use to select a current time zone.

30
00:02:00,239 --> 00:02:06,680
But nowadays, TimeDateCTL is a modern alternative, and I would recommend using that.

31
00:02:06,680 --> 00:02:09,520
Let's talk about SystemD TimeSyncD.

32
00:02:09,520 --> 00:02:17,759
SystemD TimeSyncD is a SystemD service that provides a simple NTP-based time synchronization.

33
00:02:17,759 --> 00:02:23,360
And if you are using a complex configuration, it is recommended not to use SystemD TimeSyncD.

34
00:02:23,360 --> 00:02:29,479
And that is exactly why on Reddit, you will find ChronyD instead of SystemD TimeSyncD.

35
00:02:29,479 --> 00:02:34,399
The TimeDateCTL is a common utility to work with SystemD TimeSyncD.

36
00:02:34,399 --> 00:02:41,720
And SystemD TimeDateD is a tiny daemon that can be used to control time in related settings.

37
00:02:41,720 --> 00:02:46,800
It can control the start and stop of the SystemD TimeSyncD service.

38
00:02:46,800 --> 00:02:50,520
On Reddit family, you should learn about ChronyD.

39
00:02:50,520 --> 00:02:57,119
ChronyD reads the etcchrony.conf configuration file for instructions on how to synchronize.

40
00:02:57,119 --> 00:03:01,880
And ChronyD is running on every server, because every server needs to be synchronized with

41
00:03:01,880 --> 00:03:03,779
the internet.

42
00:03:03,779 --> 00:03:08,860
If you want to check current synchronization status, you can use ChronyC Sources.

43
00:03:08,860 --> 00:03:09,860
Let me show you.

44
00:03:09,860 --> 00:03:17,339
So first, I want to show you date, which is showing that it's Wednesday, August 13, 850.

45
00:03:17,339 --> 00:03:24,339
Then I'm using TimeDateCTL TabTab, where TabTab is showing all the different commands.

46
00:03:24,339 --> 00:03:29,820
So TimeDateCTL status is giving me current information, a lot more detailed.

47
00:03:29,820 --> 00:03:36,059
So it's giving me the time zone, it's giving information about the system clock, synchronization,

48
00:03:36,059 --> 00:03:39,979
the local time versus universal time.

49
00:03:39,979 --> 00:03:45,740
And it also has commands to set the time zone if you want to.

50
00:03:45,740 --> 00:03:49,419
Now HWclock is the third command that matters.

51
00:03:49,419 --> 00:03:52,339
And HWclock is giving the hardware clock.

52
00:03:52,339 --> 00:03:55,179
And this hardware clock should be pretty close to the system clock.

53
00:03:55,179 --> 00:04:01,259
And if that is not the case, you can use the different options that are available.

54
00:04:01,259 --> 00:04:03,100
As you can see, there's a lot.

55
00:04:03,100 --> 00:04:05,419
There are only two that really matter.

56
00:04:05,419 --> 00:04:13,220
And these are minus S for hardware clock to Sys, and minus W for Sys to HC.

57
00:04:13,220 --> 00:04:17,700
So either your hardware clock is correct and the system clock is not, then you go for minus

58
00:04:17,700 --> 00:04:23,220
S. But more common is that your hardware clock is off because of a battery problem on the

59
00:04:23,260 --> 00:04:24,700
hardware clock, for instance.

60
00:04:24,700 --> 00:04:29,260
Then you set the time on the system and you synchronize it to the hardware clock.

61
00:04:29,260 --> 00:04:33,179
And after that, you will be all right.

62
00:04:33,179 --> 00:04:43,459
Now SystemCTL status on cronyd.service is showing that the cronyd service is currently loaded.

63
00:04:43,459 --> 00:04:49,540
It's also giving nice information about the service that it uses to synchronize with.

64
00:04:49,579 --> 00:04:54,739
Alternatively, you can use cronyc sources, which is giving the main information, but

65
00:04:54,739 --> 00:04:56,820
it is not as readable.

66
00:04:56,820 --> 00:05:02,059
Now what you care about in time synchronization is that you are synchronizing with a server

67
00:05:02,059 --> 00:05:04,220
that has a reliable stratum.

68
00:05:04,220 --> 00:05:08,779
The stratum indicates how close you are to the ultimate source of time.

69
00:05:08,779 --> 00:05:11,940
Stratum 1 means that you're directly on internet time.

70
00:05:11,940 --> 00:05:15,299
Stratum 2 means that you are synchronizing with stratum 1.

71
00:05:15,339 --> 00:05:20,579
Stratum 3 means that you are synchronizing with a stratum 2 and so on.

72
00:05:20,579 --> 00:05:26,940
Typically, stratum 11 is never to be found in internet synchronization because there

73
00:05:26,940 --> 00:05:30,339
will be 10 servers between the stratum 11 and the internet.

74
00:05:30,339 --> 00:05:35,260
But stratum 11 is commonly used for on-site synchronization.

75
00:05:35,260 --> 00:05:40,700
So if you want to offer your own NTP server without being connected to the internet,

76
00:05:40,700 --> 00:05:42,660
stratum 11 should be used.

77
00:05:42,739 --> 00:05:47,420
So that if ever you connect to the internet, internet time, which is more reliable, will

78
00:05:47,420 --> 00:05:49,299
always win.

79
00:05:49,299 --> 00:05:54,579
If ever you see stratum 16, that means that the server in question could not be used.

80
00:05:54,579 --> 00:06:00,220
And a configuration behind crony is in etc.crony.conf.

81
00:06:00,220 --> 00:06:06,700
So there you can see the line pool2.centOS or pool.ntp.org, which is indicating that

82
00:06:06,700 --> 00:06:09,220
it's synchronizing time from there.

83
00:06:09,220 --> 00:06:14,220
And the alternative option is server, followed by an IP address or a server.

84
00:06:14,220 --> 00:06:18,820
And that will make that you synchronize your time with that specific server.

85
00:06:18,820 --> 00:06:23,700
After adding a server, don't forget to use systemctl status on cronyd.

86
00:06:23,700 --> 00:06:29,619
And also don't forget cronyc sources to figure out if synchronization is working all right.

