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,040 Commonly used time services are in pool.ntp.org. 10 00:00:43,040 --> 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:16,720 SystemD TimeSyncD is a SystemD service that provides a simple NTP-based time synchronization. 33 00:02:17,720 --> 00:02:23,320 And if you are using a complex configuration, it is recommended not to use SystemD TimeSyncD. 34 00:02:23,320 --> 00:02:29,440 And that is exactly why on Reddit you will find ChronyD instead of SystemD TimeSyncD. 35 00:02:29,440 --> 00:02:34,360 The TimeDateCTL is a common utility to work with SystemD TimeSyncD. 36 00:02:34,360 --> 00:02:41,679 And SystemD TimeDateD is a tiny daemon that can be used to control time in related settings. 37 00:02:41,679 --> 00:02:46,759 It can control the start and stop of the SystemD TimeSyncD service. 38 00:02:46,759 --> 00:02:50,399 On Reddit family, you should learn about ChronyD. 39 00:02:50,399 --> 00:02:57,080 ChronyD reads the etcchrony.conf configuration file for instructions on how to synchronize. 40 00:02:57,080 --> 00:03:01,839 And ChronyD is running on every server, because every server needs to be synchronized with 41 00:03:01,839 --> 00:03:03,740 the internet. 42 00:03:03,740 --> 00:03:08,839 If you want to check current synchronization status, you can use ChronyC sources. 43 00:03:08,839 --> 00:03:10,720 Let me show you. 44 00:03:10,759 --> 00:03:17,320 So first I want to show you date, which is showing that it's Wednesday, August 13, 850. 45 00:03:17,320 --> 00:03:24,320 Then I'm using TimeDateCTL tab tab, where tab tab is showing all the different commands. 46 00:03:24,320 --> 00:03:28,360 So TimeDateCTL status is giving me current information. 47 00:03:28,360 --> 00:03:29,800 A lot more detailed. 48 00:03:29,800 --> 00:03:36,080 So it's giving me the time zone, it's giving information about the system clock synchronization, 49 00:03:36,080 --> 00:03:40,000 the local time versus universal time. 50 00:03:40,000 --> 00:03:45,759 And it also has commands to set the time zone if you want to. 51 00:03:45,759 --> 00:03:52,360 Now hwclock is the third command that matters, and hwclock is giving the hardware clock. 52 00:03:52,360 --> 00:03:55,199 And this hardware clock should be pretty close to the system clock. 53 00:03:55,199 --> 00:04:01,279 And if that is not the case, you can use the different options that are available. 54 00:04:01,279 --> 00:04:03,080 As you can see, there's a lot. 55 00:04:03,080 --> 00:04:05,440 There are only two that really matter. 56 00:04:05,440 --> 00:04:13,080 These are minus s for hardware clock to sys, and minus w for sys to hc. 57 00:04:13,080 --> 00:04:18,440 So either your hardware clock is correct and the system clock is not, then you go for minus s. 58 00:04:18,440 --> 00:04:24,720 But more common is that your hardware clock is off because of a battery problem on the hardware clock, for instance. 59 00:04:24,720 --> 00:04:29,320 Then you set the time on the system, and you synchronize it to the hardware clock. 60 00:04:29,320 --> 00:04:33,200 And after that, you will be all right. 61 00:04:33,200 --> 00:04:43,519 Now systemctl status on cronyd.service is showing that the cronyd service is currently loaded. 62 00:04:43,519 --> 00:04:49,559 It's also giving nice information about the service that it uses to synchronize with. 63 00:04:49,559 --> 00:04:56,799 Alternatively, you can use cronyc sources, which is giving the main information, but it is not as readable. 64 00:04:56,799 --> 00:05:02,040 Now what you care about in time synchronization is that you are synchronizing with a server 65 00:05:02,079 --> 00:05:04,239 that has a reliable stratum. 66 00:05:04,239 --> 00:05:08,799 The stratum indicates how close you are to the ultimate source of time. 67 00:05:08,799 --> 00:05:11,959 Stratum 1 means that you're directly on internet time. 68 00:05:11,959 --> 00:05:15,320 Stratum 2 means that you are synchronizing with stratum 1. 69 00:05:15,320 --> 00:05:20,559 Stratum 3 means that you are synchronizing with a stratum 2, and so on. 70 00:05:20,559 --> 00:05:26,519 Typically, stratum 11 is never to be found in internet synchronization 71 00:05:26,519 --> 00:05:30,320 because there will be 10 servers between the stratum 11 and the internet. 72 00:05:30,320 --> 00:05:35,239 But stratum 11 is commonly used for on-site synchronization. 73 00:05:35,239 --> 00:05:40,679 So if you want to offer your own NTP server without being connected to the internet, 74 00:05:40,679 --> 00:05:45,040 stratum 11 should be used so that if ever you connect to the internet, 75 00:05:45,040 --> 00:05:49,200 internet time, which is more reliable, will always win. 76 00:05:49,200 --> 00:05:54,440 If ever you see stratum 16, that means that the server in question could not be used. 77 00:05:54,440 --> 00:06:00,079 And the configuration behind crony is in etc.crony.conf. 78 00:06:00,079 --> 00:06:05,480 So there you can see the line pool2.centOS or pool.ntp.org, 79 00:06:05,480 --> 00:06:09,079 which is indicating that it's synchronizing time from there. 80 00:06:09,079 --> 00:06:14,079 And the alternative option is server, followed by an IP address or a server. 81 00:06:14,079 --> 00:06:18,559 And that will make that you synchronize your time with that specific server. 82 00:06:18,559 --> 00:06:23,600 After adding a server, don't forget to use systemctl status on cronyd. 83 00:06:23,600 --> 00:06:29,600 And also don't forget cronyc.sources to figure out if synchronization is working all right.